Hi,
to teleport a body we use remove/add rigid body which works nicely.
However, when constraints are attached to the body they of course don't know about this teleport and snap back with lotsa momentum when the body is added again.
Is there any easy solution how to handle such a situation without also removing all constraints and adding them again?
thanks
teleport constraints
-
- Posts: 6
- Joined: Thu Apr 03, 2008 7:39 pm
Re: teleport constraints
Hello. i was dealing with the same problem.
i've found that by executing the following code in my physics_tick routine *twice*, fixes my problems, with no need to remove constraints.
this is pretty much taken directly from DemoApplication::clientResetScene, except, as i mentioned, i perform it for two steps.
if i only perform this code for one step, my ragdolls spin out of control.
mOffsets contains each bodies btTransform.
i tried several different combinations of things before arriving at this solution.
hope it helps.
-rob
i've found that by executing the following code in my physics_tick routine *twice*, fixes my problems, with no need to remove constraints.
this is pretty much taken directly from DemoApplication::clientResetScene, except, as i mentioned, i perform it for two steps.
if i only perform this code for one step, my ragdolls spin out of control.
mOffsets contains each bodies btTransform.
Code: Select all
for(int i=0; i<mBodyCount; i++)
{
mBodies[i]->setWorldTransform(mOffsets[i]);
mBodies[i]->setInterpolationWorldTransform(mOffsets[i]);
mBodies[i]->activate();
mWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(mBodies[i]->getBroadphaseHandle(),mWorld->getDispatcher());
mBodies[i]->setLinearVelocity(btVector3(0,0,0));
mBodies[i]->setAngularVelocity(btVector3(0,0,0));
}
hope it helps.
-rob
-
- Posts: 229
- Joined: Sun Sep 30, 2007 7:58 am
Re: teleport constraints
hi rob,
thanks a lot for pointing on this!
thanks a lot for pointing on this!
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: teleport constraints
Just to clarify, the bodies in question are the ones being teleported that are linked by constraints, e.g., the bodyparts of a ragdoll?
Setting the world transform is the actual teleport part. Presumably the next line is only important if you are actually intending to render a few more frames before the next actual internal step, otherwise predictUnconstraintMotion will override it immediately anyway. This only prevents rendering errors, then. I'm not even sure how severe they would be -- wouldn't the object simply persist at its old location until the next internal step?
Calling activate() takes all the teleported objects out of any sleep state they may be in, otherwise if you teleport them into the air, they won't fall.
I'm not sure if the broadphase proxy stuff is needed since not performing that step will only cause additional pairs which will later be rejected during the narrowphase, right? Maybe just as an efficiency thing it's a good idea.
I assume setting the linear and angular velocities is presumably just part of the teleportation effect you want to achieve. I think it would be OK to transform the velocities according to the rotation part of the teleportation transformation? It should even be ok to add more velocity to "throw" bodies out of the teleport.
I have no idea why you needed to run it twice!
Possibly they are in the wrong order or the steps need to be refactored. I'm not sure which of those calls are independent and which are not.
Setting the world transform is the actual teleport part. Presumably the next line is only important if you are actually intending to render a few more frames before the next actual internal step, otherwise predictUnconstraintMotion will override it immediately anyway. This only prevents rendering errors, then. I'm not even sure how severe they would be -- wouldn't the object simply persist at its old location until the next internal step?
Calling activate() takes all the teleported objects out of any sleep state they may be in, otherwise if you teleport them into the air, they won't fall.
I'm not sure if the broadphase proxy stuff is needed since not performing that step will only cause additional pairs which will later be rejected during the narrowphase, right? Maybe just as an efficiency thing it's a good idea.
I assume setting the linear and angular velocities is presumably just part of the teleportation effect you want to achieve. I think it would be OK to transform the velocities according to the rotation part of the teleportation transformation? It should even be ok to add more velocity to "throw" bodies out of the teleport.
I have no idea why you needed to run it twice!
Possibly they are in the wrong order or the steps need to be refactored. I'm not sure which of those calls are independent and which are not.