Hey, trying to get movement working for this programming project I am working on, but this doesnt let the player even work, what am I doing wrong here?
local HASH_LEFT = hash("player_left")
local HASH_ RIGHT = hash("player_right")
local HASH_UP = hash("player_up")
local HASH_DOWN = hash("player_down")
function init(self)
msg.post(".", "acquire_input_focus")
--self.move_distance = 0
go.set_position(vmath.vector3(250 ,125 ,0))
self.speed = vmath.vector3(0, 0, 0)
end
function update(self, dt)
local position = go.get_position()
go.set_position(position + self.speed * dt)
if (go.get_position().x < 50) then
self.speed.x = 50
end
if (go.get_position().x > 50) then
self.speed.x = -50
end
if (go.get_position().y < 50) then
--self.speed.y = 50
end
if (go.get_position().x > 50) then
self.speed.x = -50
end
end
function on_input(self, action_id, action, dt)
if action_id == HASH_LEFT then
if action.presed then
self.speed.x = -50
elseif action.released then
self.speed.x = 0
end
return true
end
if action_id == HASH_RIGHT then
if action.presed then
self.speed.x = 50
elseif action.released then
self.speed.x = 0
end
return true
end
if action_id == HASH_UP then
if action.presed then
self.speed.y = 50
elseif action.released then
self.speed.y = 0
end
return true
end
if action_id == HASH_DOWN then
if action.presed then
self.speed.y = -50
elseif action.released then
self.speed.y = 0
end
return true
end
end```