How to Rotate an object in a collision event??

What I am trying to do it is, two object collide each other, then one of them will move to the center point of the other object. What I did is I use the “transition.to” in the collision event, which works fine…
but now I want to change the angle of the moving object before the transition so that it makes the object head facing to the moving direction.

But once I try to set the object to rotate, the Corona Simulator complains:

“ERROR: Cannot rotate an object before collision is resolved.”
Anyone has any idea how I can rotate an object once it collides with other object?

Thanks

[import]uid: 38556 topic_id: 14980 reply_id: 314980[/import]

try doing it in pre-collision
[lua]object:addEventListener(“preCollision”, preCollissionFunction)[/lua] [import]uid: 71210 topic_id: 14980 reply_id: 55283[/import]

I probably do it in the worst way possible but it works!

[code]

right = false

– collision
collisionobj.collision = function(self, event)
if(event.phase == “ended”) then
right = “true”
print(“collision touched”)

end
return true
end

— collisionobj collision listener
collisionobj:addEventListener(“collision”, collisionobj)

local function listener( event )
if(right == “true”) then

obj.rotation = obj.rotation + 1
print( “rotation started” )

end
end

timer.performWithDelay( 100, listener, -1 )
– ^ lower that number to fastenen the spin or obj.rotation + (higher number than 1) [import]uid: 24708 topic_id: 14980 reply_id: 55325[/import]

Hi Renvis, is there any tricks to use the Pre/Post Collision? I just can’t get it working in my code

[import]uid: 38556 topic_id: 14980 reply_id: 55673[/import]

Can I have your code with the part you are facing trouble with ?
It will be easier for me to work on that and find a fix. :slight_smile: [import]uid: 71210 topic_id: 14980 reply_id: 55674[/import]

I guess I know why Post/Pre Collision doesn’t work on my code. I defined all the physics body “isSensor=true” with Collision Filter. A standard collision event works fine but seems like Post/Pre Collision doesn’t work with Collision Filter…damn…is it a Bug ? or this is the way how Post/Pre Collision works? [import]uid: 38556 topic_id: 14980 reply_id: 55687[/import]