I’m trying to move a game object (with a sprite) using the following code:
go.property("speed", 5)
function init(self)
msg.post(".", "acquire_input_focus")
self.velocity = vmath.vector3()
end
function update(self, dt)
self.velocity = vmath.normalize(self.velocity)
local position = go.get_position()
print(position)
position = position + self.velocity * self.speed * dt
go.set_position(position)
self.velocity = vmath.vector3()
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.velocity.y = 1
end
if action_id == hash("down") then
self.velocity.y = -1
end
if action_id == hash("left") then
self.velocity.x = -1
end
if action_id == hash("right") then
self.velocity.x = 1
end
end
However, when I add this script component to the game object. The sprite is no longer visible.
I tried to print the position value (as shown here) but it prints a vector with nil values.
I cannot manage th find my error. Any help?