Spheres show strange behaviour.

Post Reply
trying
Posts: 15
Joined: Sat May 16, 2015 4:32 pm

Spheres show strange behaviour.

Post by trying »

Hello Bullet Physics Community,

I am new to Bullet and as well as this forum, too. I am facing a major problem with the behaviour of spheres when colliding with each other in mid air. There are 2 spheres with their own gravity and restitution. When they fall, Sphere 1 collides with Sphere 2 and Sphere 1 goes in the upward direction due to the restitution, it was expected that Sphere 1 will tend to fall again but instead of falling it stopped after coming down few centimeters. Also, Sphere 2 stops as well, after coming down few meters.

Sphere 1: Gravity = -0.7 Restitution = 0.8 ( `-` downwards)
Sphere 2: Gravity = 0.4 Restitution = 0.8 ( `+` upwards)
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Spheres show strange behaviour.

Post by drleviathan »

Bullet will deactivate moving objects that are going slow enough for a long enough period of time. When the spheres reach the top of their arc they are moving slowly so they are candidates for deactivation. You can change the threshold velocities (linear and angular) at which objects are considered "slow" on a per-object basis, however the duration for which they need to be moving slowly before they are deactivated is a system-wide setting and is, if I remember correctly, currently hard coded to 2 seconds.

Use btRigidBody::setSleepingThresholds() to set the linear and angular velocity thresholds for "slow".
trying
Posts: 15
Joined: Sat May 16, 2015 4:32 pm

Re: Spheres show strange behaviour.

Post by trying »

drleviathan wrote: Use btRigidBody::setSleepingThresholds() to set the linear and angular velocity thresholds for "slow".
Thank you for your reply.

What values are fit for linear and angular velocities?


EDIT: What is the difference between world gravity and rigid body gravity ? Does rigidbody gravity gets affected by the world gravity ?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Spheres show strange behaviour.

Post by drleviathan »

In Bullet 2.8.2 the default values for linear and angular sleeping velocities are: 0.8 m/sec and 1.0 radians/sec respectively. These are hard-coded magic numbers in the btRigidBody constructor implementation.

You'll have to experiment with different values to find something that works for you, although if you want to keep ballistic objects from sleeping at the top of their arc you probably want to keep the sleeping velocity near or below the speed that a falling object gains after two substeps, which depends on the gravity and subsetp settings:

maximum_sleeping_velocity = 2.0 * strength_of_gravity * substep_duration

Gravity is set on a per-object basis in Bullet, however the btDiscreteDynamicsWorld (which I assume you're using) will automatically set the gravity of each object to that of the world... unless the BT_DISABLE_WORLD_GRAVITY bit is set in the RigidBody's flags (via btRigidBody::setFlags()) in which case the object will use whatever gravity has been manually set.
trying
Posts: 15
Joined: Sat May 16, 2015 4:32 pm

Re: Spheres show strange behaviour.

Post by trying »

I set the linear and angular velocity to 0.0 and they are working as I wanted them to work. Thank you.
I'll look into the flags.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Spheres show strange behaviour.

Post by drleviathan »

If you set the sleeping velocity thresholds too low then your objects will never settle! If you want that behavior just for those objects (and not the rest of the world) you can call btRigidBody::setActivationState(DISABLE_DEACTIVATION) instead.
trying
Posts: 15
Joined: Sat May 16, 2015 4:32 pm

Re: Spheres show strange behaviour.

Post by trying »

I do not want them to stop while in air. By the way, can they be stable on land if friction is applied to them.
Post Reply