I’m developing a game just for fun, but i came across a bug of the movement of the player that im just can’t understand. My knowledge of programming is pretty basic (i studied C in colege) and based in codes of forums that i found here.
Basically the bug is that the game does not accept two inputs at the same time.
Like, if im pressing the action D the player go to the right, and if i press the action A (with D still pressed) the player go to the left, but if i let go A the player just stops like any action is pressed.
function init(self)
msg.post('.', 'acquire_input_focus')
self.velocity_direction = vmath.vector3()
self.velocity_module = 60
self.direction = vmath.vector3()
end
function update(self, dt)
self.current_position = go.get_position()
self.new_position = self.current_position + self.velocity_direction * self.velocity_module * dt
go.set_position(self.new_position)
end
function on_input(self, action_id, action)
if action_id == hash('left') and action.pressed then
self.velocity_direction.x = -1
self.direction.x = -1
msg.post('player', "play_animation", {id = hash('player_run_left')})
elseif action_id == hash('right') and action.pressed then
self.velocity_direction.x = 1
self.direction.x = 1
msg.post('player', "play_animation", {id = hash('player_run_right')})
end
if action.released and self.direction.x == -1 then
self.velocity_direction.x = 0
msg.post('player', "play_animation", {id = hash('player_idle_left')})
elseif action.released and self.direction.x == 1 then
msg.post('player', "play_animation", {id = hash('player_idle_right')})
self.velocity_direction.x = 0
end
end