Stopping time for an object

Post Reply
davis
Posts: 2
Joined: Thu Jan 19, 2012 3:44 pm

Stopping time for an object

Post by davis »

Hi!

I'm developing a game which will be based in physic interaction with objects. Our main character will have the power to stop time, but just for one object at a time.

For example, if the character throws a box and uses his power while the box is still "flying" it should stop moving and remain static in the air. Other objects should be able to collide with the box when it is "freezed". After "unfreezing" the box it should continue "flying" as if time had never been stopped.

I've been playing with bullet and seemed to achieve this result by switching the mass of the object to 0 ("switching" it to static) as well as changing its Linear and Angular velocity to 0,0,0. To "unfreeze" the object I just put back the orginal values.

The problem is that sometimes it does strange things (objects not colliding correctly with the freezed object or flying away of it).

I'm pretty sure this is not the best way to achieve this result. Could you give me a better solution to my problem?

Thank you in advance!

David
kloplop321
Posts: 55
Joined: Sun Jan 01, 2012 7:37 pm

Re: Stopping time for an object

Post by kloplop321 »

Eh.. Why don't you just keep a buffer somewhere in your code that contains information about the freezed object. Then when the player freezes it, it copies the transform, the shape pointer, and the things like linear and angular velocity.
Then remove that body from the world, but not the shape, and then create a new one with the same transform that is a static body.
Do this before stepping the world.
Keep a pointer to that body and when the player tries to unfreeze it, remove the static body, use the information in the first-mentioned buffer to recreate the dynamic body and let the world continue.

It might just be a matter of changing flags, but that's a solution I see.
davis
Posts: 2
Joined: Thu Jan 19, 2012 3:44 pm

Re: Stopping time for an object

Post by davis »

Hi!

Thanks for your answer.

Yes, I just tried that before reading you and It seems to work, at least it has worked in every test I've done.

The only difference is that I don't use a new body, I just change its parameters (mass, linear/angular velocity = 0) once it has been removed from the world and then re-introduce it. I use the same method when unfreezing the object.

Also when unfreezing the object I have to recalculate the localinertia

body->getCollisionShape()->calculateLocalInertia(mass,localInertia);

using (0,0,0) as localInertia.

Thank you for your help. I hope this helps someone else!

David
Post Reply