Rolling spheres turning into zombie spheres

tkefauver
Posts: 10
Joined: Fri Jul 19, 2013 11:32 pm

Rolling spheres turning into zombie spheres

Post by tkefauver »

I'm making a pool simulator and everything looks great after a hit until the balls begin to slow down... They decelerate fine for a while but will ultimately fall into this natural roll and begin exhibiting zombie-like behavior - rolling in random directions and even speeding back up sometimes!

I had been using a triangle mesh as the table surface but read that the vertices can influence a sphere rolling on it's velocity but get the same behavior with a static plan instead. The sphere's representing the ball's are small (0.028m) but I've read on here that scale shouldn't be a problem anymore. I have experimented with many different rollingFriction values in both the ball and the table surface, still zombie mayhem. Also I have tried many damping variations to curtail this but it either is not enough to prevent the zombie plague or the ball's stop way too abruptly.

I have read on stackoverflow and other places that rolling friction applies friction to the point of the body in contact with the surface (see http://stackoverflow.com/questions/1851 ... _18518950). Since its not applied to the centroid it should affect both the linear and angular velocities but in my case, once the ball is going slow it seems to have no affect.

If this should work which I think it should, does anyone know any gotcha's I could be missing? Or maybe using additionaldamping somehow perhaps?

If I need to implement my own version of rollingFriction for this behavior does anyone have any suggestions?
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Rolling spheres turning into zombie spheres

Post by bwelch »

Do you use the setAnisotropicRollingFriction() function? I'm still pretty new to Bullet, but I've seen this used where rolling friction is used (like in the rolling friction demo).
tkefauver
Posts: 10
Joined: Fri Jul 19, 2013 11:32 pm

Re: Rolling spheres turning into zombie spheres

Post by tkefauver »

Yes I am using setAnisotropicRollingFriction. I hadn't been for a long time while testing this but it does seem to make the movement more realistic (but it still never stops!). One thing I'm confused about is do I specify rolling friction onto the sphere or the body the sphere will be rolling on? Adding rollingFriction to the table surface has the same effect as adding it to the sphere, but not adding it to both, then it seems to cancel out and not roll at all! In either case though, the balls still never come to rest. Could this be some sort of time step issue maybe?

Right now I made a check called "throttleBalls" before each timestep that does the following:

Code: Select all

if(ball->body->getLinearVelocity().length < BALL_THROTTLE_VELOCITY) {
ball->body->setLinearVelocity(ball->body->getLinearVelocity().normalized()*(ball->body->getLinearVelocity().length()*0.75));
}
Which semi-abruptly stops the balls and it looks like crap but they stop...If I reduce BALL_THROTTLE_VELOCITY, the ball never becomes slow enough to trigger it and conversely if I use a higher reduction ratio than 0.75 than whatever is forcing them to keep moving overcomes the reduction so it just keeps on rolling.

This is a very hacky way of fixing this problem and I'd really like to figure out what's wrong with my setup.

Also thank you @bwelch for actually answering me! I've asked like 4-5 questions on this forum and just get crickets everytime.
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Rolling spheres turning into zombie spheres

Post by bwelch »

tkefauver wrote:One thing I'm confused about is do I specify rolling friction onto the sphere or the body the sphere will be rolling on?
From what I've read and toyed about with, you have to specify rolling friction on both objects. In the rolling friction demo, they set the friction on the ground shape like:

Code: Select all

body->setFriction(1);
body->setRollingFriction(1);
And the friction on the rolling shapes like:

Code: Select all

body->setFriction(1.f);
body->setRollingFriction(.3);
body->setAnisotropicFriction(colShape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
If you've tried adding friction to both the pool balls and the table and the balls stop, maybe it's just a matter of decreasing the friction values? I've not been able to determine whether the value passed to setFriction is the same as the scientific coefficient of friction or not (it hasn't been necessary for my use of Bullet), but toying with the values has given me good enough results.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Rolling spheres turning into zombie spheres

Post by SynapticBytes »

Normal friction does not work on a sphere, as there is only a single contact point. You need at least 2 contact points for normal friction to have an effect. This is where rolling friction comes in, so for a sphere this is what you should be using, and yes, you need to set it on both bodies in contact. Friction values should be between 0 for no friction, and 1 for 100% friction.

I wouldn't think anisotropic friction should be used, as that is friction along an axis.

Your ball size does seem rather small. I can't remember offhand whether the mass affects friction results? Try upping the size and/or mass and see if that has any effect.

You could check your sleeping thresholds as we'll, although given the behaviour you've described, I'm not sure that will help.

Also, as an experiment trying a box shape for your table instead of a plane and see if it makes any difference.
tkefauver
Posts: 10
Joined: Fri Jul 19, 2013 11:32 pm

Re: Rolling spheres turning into zombie spheres

Post by tkefauver »

You're right @SynapticBytes I don't need ansiotropic friction. That would only apply to something like a wheel that only rolls on one axis (found more info http://www.blender.org/documentation/in ... 0Friction?)

I've looked closely at the rolling friction demo and they are indeed specifying a rolling friction for both the sphere and surface. When I try this though my ball only skids (no angular velocity) when both ball and surface have positive rolling friction values. I thought this may be a weird side effect of the ball's having such low relative masses but increasing it still doesn't stop the skidding. Using really low rolling friction values, like 0.1 and 0.01 for the surface and sphere respectively, gains me some angular velocity briefly but then goes right on back to just skidding!

I went line by line through the demo and my setup 'appears' identical to it, except I'm setting a restitution of 0.5 for the ball...

So obviously I'm missing something here! Any ideas what 'that' might be? I know these kind of problems are hard to troubleshoot but your wild guesses are probably better than mine.
tkefauver
Posts: 10
Joined: Fri Jul 19, 2013 11:32 pm

Re: Rolling spheres turning into zombie spheres

Post by tkefauver »

Also just throwing this out there but after my frustrations had a thought that it would be nice if the wiki had a section covering how the btRigidBody properties interact one another and influence velocity. And like you mentioned @bwelch, some info on how to translate scientific values into bullet equivalents.

I know the info is peppered throughout the forum, but having it in one cohesive doc would probably help a lot of people! Wish I could do it, but obviously I'm still grabbing at straws here...
tkefauver
Posts: 10
Joined: Fri Jul 19, 2013 11:32 pm

Re: Rolling spheres turning into zombie spheres

Post by tkefauver »

One other odd thing that might shed light on what's wrong with my setup: at the beginning of the simulation the balls are slightly higher than the table surface and (should) just drop the minute distance to rest. But instead they immediately start rolling in odd directions but will eventually slowly collect in one corner (same every time). I'm currently debugging this with a flat static plane as my surface (as opposed to my tri mesh) and the balls are initialized with a WANTS_DEACTIVATION activationState.

Could this have something to do with sleep thresholds? I've tried different values and have been assuming that its thresholding velocity, is that correct?