Problem setting position of game object (SOLVED)

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

2 Likes

Where is it that you are testing that the input is being received?

If you put

print("!")

Inside the if action.pressed loop, does it print?

1 Like

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.)

3 Likes

I have now sort of solved the problem. I removed the collision object and it suddenly started working. Any idea why this would be?

2 Likes

If the collision object is set to dynamic it will itself set the position each frame based on the physics calculations. :slight_smile: You could change it to kinematic or static instead.

3 Likes

Thanks, will try that now

3 Likes

I set the collision model to static and now it works fine. Thanks for the fast reply.

3 Likes