I am having a problem setting the position of a game object. The code I am using is
function on_input(self, action_id, action)
if action_id == hash("left") then
if action.pressed then
local pos = go.get_position()
pos.x = pos.x - 100
go.set_position(pos)
end
The input is being received but then the position is not changing. Please help. I am very new to Defold, though i have past experience in lua
The code looks correct… Is it the correct game object you have attached the script to that you want to set the position for? (If you don’t specify the game object id in go.set_position it will be the same that the script is attached to.)
If the collision object is set to dynamic it will itself set the position each frame based on the physics calculations. You could change it to kinematic or static instead.