Constant gravity

cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Constant gravity

Post by cobolt_dink »

This might sound stupid, but is there any way to have gravity pull on a sleeping rigid body? If you have two rigid bodies stacked on top of each other and remove the bottom the top just hangs in space because its alseep. I know you could just activate it and it would fall. But that means you either have to have each rigid body know what other rigid body its in contact with or just activate them all whenever any kind of physics action occurs. The other option I guess would be to make them never go to sleep but then there is that much more CPU thats pretty much being wasted every frame. I hope I'm just missing something as either of those solutions isn't real appealing.
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: Constant gravity

Post by cobolt_dink »

I know I can't be the only person to have needed something like this.
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: Constant gravity

Post by ola »

Can you try to activate the body that you remove, before you remove it? That would wake up any other bodies that intersect it's bounding box. Maybe you will have to activate it one iteration before you remove it, have not tried this myself.

Cheers,
Ola
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: Constant gravity

Post by cobolt_dink »

I didn't know that activating a body would activate all the bodies it touching. You still have to apply an impulse to the original body to make them get gravity applied to the others. But that doesn't always seem to work right.

When the object is deleted I activate the body and then apply a 'up' impulse to the body. This adds the rigid body to a list that deletes the rigid body after the next frames stepSimulation(). This works sometimes. If I have several blocks stacked on top of each other taking out the bottom one will cause the others to drop only for the first couple. After that they hang in the air like they didn't get activated. I can kind of get around this by letting four or five frames go by before deleting the body. But that is a nasty hack that could be a real problem if the frame rate drops to much and things are colliding with invisible bodys. Any suggestions or other ideas?
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: Constant gravity

Post by cobolt_dink »

I messed around with this some more and think I have something figured out. Before I was using a variable timestep for physics and for some reason it seems like rigid bodies don't aways get activated when one touching them does. I tried going to a fixed timestep and it seems to work but I still have to give a fairly big (5*mass) impulse to the removed object to get all the stacked objects to wake up. Anybody have any ideas why this would happen like this?