Preventing Rigid Bodies from being pushed

Post Reply
Adman
Posts: 3
Joined: Mon Mar 30, 2015 5:00 pm

Preventing Rigid Bodies from being pushed

Post 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!
RazzorFlame
Posts: 5
Joined: Sun Mar 08, 2015 2:31 pm

Re: Preventing Rigid Bodies from being pushed

Post 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.
Adman
Posts: 3
Joined: Mon Mar 30, 2015 5:00 pm

Re: Preventing Rigid Bodies from being pushed

Post 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.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Preventing Rigid Bodies from being pushed

Post 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:
Adman
Posts: 3
Joined: Mon Mar 30, 2015 5:00 pm

Re: Preventing Rigid Bodies from being pushed

Post 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?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Preventing Rigid Bodies from being pushed

Post 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.
Post Reply