physics.addBody question

Hi there,

I'm basically trying do do a kind of teleport when an object hits another.
I'm using the physics-engine for collision-detection.

So first I created a 'door' which teleports an object to another 'door'.
The door has the isSensor-flag enabled and correctly detects a collision with the (moving) object. If I just try to change the x/y-coordinates as soon as the collision begins, I get an 'Cannot translate an object before collision is resolved'-Error. So far so good. I first tried to simply pause physics using physics.pause(), do the translation and the restart physics again, but that didn't work (same error). I then tried to delete the object on collision using object:removeSelf(), then created the object again at its new position and added the physics-body again.
This worked, but the physics-body is not added to the object again, therefore no collisions anymore..

What am I doing wrong, how can I add the body to the object again or what is a better way to do the translation during the collision?

And btw, the object is moving through the sensor during the collision by adding vals to the object.x-value, how comes this is possible, while doing so for the teleport throws out the error-message?

Hope you got what I mean...

Greets,
Dschonny

Try moving the code where you change the coordinates of your object to a new function and then call it with 1 millisecond delay via timer.performWithDelay()

Raúl Beltrán
MIU Games

Still doesn't solve my problem... When just doing the transition with a delay, I get the same error as before (because the collision event still is in 'began'-phase cause the player is still touching the door?), if I use the remove/create-way and try to delay adding the body, it still just does not receive a physics-body again...

Tried different delay-times up to 100 millisecs..

Any other hints?

PS: Solved it by using a flag and doing the transition in the enterFrame-Event instead of inside the collision-event, thanks for looking into it anyways..

change body to static then move then change body back to dynamic

views:1587 update:2011/10/22 9:46:13
corona forums © 2003-2011