There is an issue with my jump for my character, when jump is pressed the y value increases but i dont know how to get the player back to the ground.
local jump_speed = 400
-- Initalise the script
function init(self)
msg.post(".", "acquire_input_focus")
self.vel = vmath.vector3()
self.anim = nil
end
-- movement
function update(self, dt)
local pos = go.get_position()
pos = pos + self.vel * dt
go.set_position(pos)
self.vel.x = 0
self.vel.y = 0
end
--keyboard input
function on_input(self, action_id, action)
if action_id == hash("left") then
play_animation(self, (hash "walk_hero"))
sprite.set_hflip("#sprite", true)
self.vel.x = -200
elseif action_id == hash("right") then
play_animation(self, (hash "walk_hero"))
sprite.set_hflip("#sprite", false)
self.vel.x = 200
elseif action_id == hash("up") then
play_animation(self, (hash "jump_hero"))
self.vel.y = jump_speed
end
end
thanks