Page 1 of 1

Preventing Rigid Bodies from being pushed

Posted: Mon Mar 30, 2015 5:03 pm
by Adman
Hello!

I have 2 rigid bodies being moved around my scene by setting their linear velocity. I dont want them to be able to be pushed by each other when they collide (or being pushed by any other rigid body, for that matter). How do I go about this?

Thanks!

Re: Preventing Rigid Bodies from being pushed

Posted: Mon Mar 30, 2015 6:43 pm
by RazzorFlame
Set mass to 0, recalculate inertia and set them with btRigidBody::setMassProps(btScalar mass, btVector3 inertia)
This will make them kinematic, now they cannot be affected with any force, even gravity.

Re: Preventing Rigid Bodies from being pushed

Posted: Mon Mar 30, 2015 6:53 pm
by Adman
RazzorFlame wrote:Set mass to 0, recalculate inertia and set them with btRigidBody::setMassProps(btScalar mass, btVector3 inertia)
This will make them kinematic, now they cannot be affected with any force, even gravity.
I understand setting the mass to 0 will make them immovable, however Im still trying to have them not only be affected by gravity, but be moveable from setLinearVelocity too. I just want them to be unable to push each other. Using setMassProps to set the mass to 0 then back to the previous mass doesnt prevent this either.

Re: Preventing Rigid Bodies from being pushed

Posted: Tue Mar 31, 2015 3:35 am
by Basroil
Adman wrote: I understand setting the mass to 0 will make them immovable
0 mass means not dynamic, not necessarily immovable. Basically anything they do affects dynamic objects but not the other way around. In fact, other kinematic objects don't affect it either.
Adman wrote: however Im still trying to have them not only be affected by gravity, but be moveable from setLinearVelocity too. I just want them to be unable to push each other. Using setMassProps to set the mass to 0 then back to the previous mass doesnt prevent this either.
What is gravity? It's just a constant acceleration (for what you want), which is the same as just linearly increasing velocity. setLinearVelocity can simply take in your current velocity + a gravity constant for your simulation rate + your externally derived velocity change. You'll end up with an object that moves according to what you want, which falls due to gravity, and isn't affected by anything else but still pushes dynamic objects. Just make sure to take care of your own collision and restitution or you'll be falling through the floor :wink:

Re: Preventing Rigid Bodies from being pushed

Posted: Tue Mar 31, 2015 8:43 am
by Adman
Basroil wrote:setLinearVelocity can simply take in your current velocity + a gravity constant for your simulation rate + your externally derived velocity change. You'll end up with an object that moves according to what you want, which falls due to gravity, and isn't affected by anything else but still pushes dynamic objects.
I tried this, every time I set the mass to 0, I cant move it via setLinearVelocity. Am I doing something wrong?

Re: Preventing Rigid Bodies from being pushed

Posted: Wed Apr 01, 2015 1:33 am
by Basroil
Adman wrote:
Basroil wrote:setLinearVelocity can simply take in your current velocity + a gravity constant for your simulation rate + your externally derived velocity change. You'll end up with an object that moves according to what you want, which falls due to gravity, and isn't affected by anything else but still pushes dynamic objects.
I tried this, every time I set the mass to 0, I cant move it via setLinearVelocity. Am I doing something wrong?
Try this: http://bulletphysics.org/mediawiki-1.5. ... tic_Bodies

Kinematic bodies are a bit more work intensive than dynamic ones for setup, but the tradeoff is that you can control exactly what it does.