Problem teleporting dynamic objects

iZiMO
Posts: 7
Joined: Thu Jul 31, 2008 11:31 pm

Problem teleporting dynamic objects

Post by iZiMO »

Hey guys,

I've tried removing the rigid body from the dynamics world, moving it, and then adding it back again as described in this post, which works fine unless the object i'm teleporting has reached a rest state.

If i teleport a falling object it will teleport no worries, and maintain it's velocity, etc. However if i teleport the object once it has hit the ground and come to a complete stop it moves to it's new location but is no longer affected by gravity.

This is the method i'm using to remove the object from the world and move it to a new location:

Code: Select all

//remove
dynamicsWorld->removeRigidBody( body ); 

//move
btTransform newTrans = body->getWorldTransform();
newTrans.setOrigin( newLocation );
newTrans.setRotation( newRotation );
body->setWorldTransform( newTrans );

//add again
dynamicsWorld->addRigidBody( body );
Is there something i'm missing?

Any help is appreciated..
Cheers
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Problem teleporting dynamic objects

Post by chunky »

One the body comes to rest it's being deactivated.

Try a simple body->activate(true)

Alternatively, disable deactivation on the body altogether in the first place, with a body->setActivationState(DISABLE_DEACTIVATION);

Gary (-;
iZiMO
Posts: 7
Joined: Thu Jul 31, 2008 11:31 pm

Re: Problem teleporting dynamic objects

Post by iZiMO »

Adding this line seems to have done the trick:

Code: Select all

body->setActivationState( DISABLE_DEACTIVATION );
I'm gonna keep testing... but is this the correct way to go?
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Problem teleporting dynamic objects

Post by chunky »

Well, that disables deactivation on that body. That body will burn a little CPU every tick, even when it's sitting not moving.

If the body spends most of the time moving [eg, if it's your player object or something they're directly controlling], then it doesn't really matter.

If it's one of many hundreds of thousands of bodies that you occasionally teleport in and then sit still after they're done moving for the next hour, then you should probably activate them individually.

Gary (-;
iZiMO
Posts: 7
Joined: Thu Jul 31, 2008 11:31 pm

Re: Problem teleporting dynamic objects

Post by iZiMO »

Thanks a lot for the speedy reply.. Exactly what i was after :]