Hi all,
I am trying to move a character when the “right” key is pressed but it seems I am not doing it the correct way.
This is my attempt:
local direction = 0
-- ...........
function update(self, dt)
local pos = go.get_position()
local new_position = pos.x + direction
go.set_position(vmath.vector3(new_position,0,0))
end
function on_input(self, action_id, action)
if action_id == hash("right") then
print("Right key pressed")
direction = 1
end
end
I can see in the console that the debug message “Right key pressed” is printed but my character does not move. I suspect the error is related to the way I try to update the game object’s position. My logic is the following: get current position, increment the x coordinate by 1, and then set this new position.
Would appreciate your help.