Hi there!
How do I make my player’s movement more smoother?
If pressed the up button — game object should move by 128 pixels on the y-coordinate. If pressed the down button — game object should move by -128 pixels on the y-coordinate. So my game object has 4 movements: from center to top, from top to center, from center to bottom and from bottom to center.
function init(self)
msg.post(".", "acquire_input_focus")
self.movement = false
self.targetPos = vmath.vector3()
self.maxYCoord = 696
self.minYCoord = 440
end
function update(self, dt)
if self.movement then
local pos = go.get_position()
pos = pos + self.targetPos
go.set_position(pos)
end
self.targetPos.y = 0
self.movement = false
end
function on_input(self, action_id, action)
if action_id == hash("up") and action.pressed and go.get_position().y < self.maxYCoord then
self.targetPos.y = 128
self.movement = true
elseif action_id == hash("down") and action.pressed and go.get_position().y > self.minYCoord then
self.targetPos.y = -128
self.movement = true
end
end
P. S. Sorry for my English.