Cannot translate an object before collision is resolved.

I get this error when I try to set the x and y coordinates.

When my ball touches an object, I want to reset that object, move it to start position.

So I have a collision detection and postCollision.

If the ball hits a certain object, I want to move the ball to center of screen, so I have this function f.ex :

[lua]local function onCollision(e)
if (e.other.name ==“leftwall” or e.other.name == “rightwall”) then
ball.x = W/2
ball.y = H/2
end
end[/lua]

Even if this is postCollision, I get the above error, and the ball is not moved.
[import]uid: 61610 topic_id: 11077 reply_id: 311077[/import]

I kind of found the answer to the question.

This works

[lua]transition.to(ball, {x = W/2, y= H/2, time=0})[/lua] [import]uid: 61610 topic_id: 11077 reply_id: 40267[/import]

You have to be really careful what you do inside collision event handlers. I haven’t figured out all the rules, but modifying the objects involved in the collision, in almost ANY way, usually causes it to crash. I wish this was documented - it’s only in the forums - because this is a pretty standard thing to do.

The workaround is simply to set a timer to call the REAL collision handler after 1ms. You can even use a lua closure to pass the same variables to this new function:

[lua]timer.performWithDelay(1,function() return realCollisionHandler( self, event) end )[/lua]

That’s why your transition.to worked - because it sets up timers to move the object. [import]uid: 49372 topic_id: 11077 reply_id: 40295[/import]

This definitely works. I was trying to reset the position of an object when it collided. This is my implementation for those who are wondering.

[lua]function crash(event)
timer.performWithDelay(1,function() return realCollisionHandler(event) end )
end

function realCollisionHandler(event)
myobject.x=resetPosition.x
myobject.y=resetPosition.y
end[/lua]

Where crash is the listener function for “collision”

[import]uid: 45119 topic_id: 11077 reply_id: 78432[/import]