hey, guys , sorry for disturbing you constantly, but i created 2 kinematic objects and I copied the content of the scripts of the objects and made some subtle changes with regard to URLs etc. The problem is : when I move an object, the other drops a few pixels until it loses contact with the ground and falls. Additionally, the masks of the respective objects are not linked, so that i cant understand what’s is their bond. For example: if a move character X, character Y’s position decreases a little amount of pixels and vice versa. Anyone knows the reason ???
being more precise: this happens after releasing the action button
there’s the code:
go.property("speed", 200) -- the speed of movement
local jump_height = 300
-- play animation unless the same animation is already playing
local function play_animation(self, animation)
if self.current_animation ~= animation then
self.current_animation = animation
msg.post("#sprite", "play_animation", { id = animation })
end
end
function on_message(self, message_id, message, sender)
-- Handle collision
if message_id == hash("contact_point_response") then
print("Contact!")
end
end
function init(self)
msg.post(".", "acquire_input_focus")
self.direction = vmath.vector3(0, 0, 0) -- the current direction of movement
self.actions = {} -- mapping of input states (action_id mapped to pressed state)
self.current_animation = nil -- the current animation
self.speed = 0
self.fall = true
msg.post("@system:", "toggle_physics_debug")
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self, dt)
if self.fall then
self.p = go.get_position()
self.p.y = self.p.y - 500 * dt
go.set_position(self.p)
end
if self.actions[hash("up")] then
self.count = 0
if self.fall == false then
play_animation(self, hash("jump"))
self.posicao = go.get_position()
self.posicao.y = self.posicao.y + (self.speed * 6) * dt
if self.posicao.y <= 600 then
go.set_position(self.posicao)
else
self.fall = true
end
else
self.fall = true
end
end
if self.actions[hash("left")] then
play_animation(self, hash("run"))
sprite.set_hflip("#sprite", true)
self.direction.x = -self.speed
elseif self.actions[hash("right")] then
play_animation(self, hash("run"))
sprite.set_hflip("#sprite", false)
self.direction.x = self.speed
else
self.direction.x = 0
end
if self.direction.x == 0 and self.direction.y == 0 then
play_animation(self, hash("idle"))
end
go.set_position(go.get_position() + self.direction * dt)
msg.post("@render:", "draw_text", { text = "Move using arrow keys", position = vmath.vector3(10, 100, 0) } )
self.atual = go.get_position()
print(self.atual)
end
function on_input(self, action_id, action)
if action_id then
if action.pressed then
self.actions[action_id] = true
elseif action.released then
self.actions[action_id] = false
self.fall = true
end
end
end
function on_message(self, message_id, message, sender)
-- Handle collision
if message_id == hash("contact_point_response") then
self.fall = false
end
end
this is the first character’s code, now see the player 2’s code :
go.property("speed", 200) -- the speed of movement
-- play animation unless the same animation is already playing
local function play_animation(self, animation)
if self.animacao_atual ~= animation then
self.animacao_atual = animation
msg.post("#sprite2", "play_animation", { id = animation })
end
end
function on_message(self, message_id, message, sender)
-- Handle collision
if message_id == hash("contact_point_response") then
end
end
function init(self)
msg.post(".", "acquire_input_focus")
self.direcao = vmath.vector3(0, 0, 0) -- the current direcao of movement
self.acoes = {} -- mapping of input states (action_id mapped to pressed state)
self.animacao_atual = nil -- the current animation
self.velocidade = 0
self.caiu = true
msg.post("@system:", "toggle_physics_debug")
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self, dt)
if self.caiu then
self.p1 = go.get_position()
self.p1.y = self.p1.y - 500 * dt
go.set_position(self.p1)
end
if self.acoes[hash("player2_up")] then
self.count = 0
if self.caiu == false then
play_animation(self, hash("jump"))
self.posicao1 = go.get_position()
self.posicao1.y = self.posicao1.y + (self.speed * 6) * dt
if self.posicao1.y <= 600 then
go.set_position(self.posicao1)
else
self.caiu = true
end
else
self.caiu = true
end
end
if self.acoes[hash("player2_left")] then
play_animation(self, hash("run"))
sprite.set_hflip("#sprite2", true)
self.direcao.x = -self.speed
elseif self.acoes[hash("player2_right")] then
play_animation(self, hash("run"))
sprite.set_hflip("#sprite2", false)
self.direcao.x = self.speed
else
self.direcao.x = 0
end
if self.direcao.x == 0 and self.direcao.y == 0 then
play_animation(self, hash("idle"))
end
go.set_position(go.get_position() + self.direcao * dt)
msg.post("@render:", "draw_text", { text = "Move using arrow keys", position = vmath.vector3(10, 100, 0) } )
self.atual = go.get_position()
print(self.atual)
end
function on_input(self, action_id, action)
if action_id then
if action.pressed then
self.acoes[action_id] = true
elseif action.released then
self.acoes[action_id] = false
self.caiu = true
end
end
end
function on_message(self, message_id, message, sender)
-- Handle collision
if message_id == hash("contact_point_response") then
self.caiu = false
end
end
Note: the variables means the same thing, but they are in portuguese (my first language).