Constant jitter and high "slippage" of wheels in motox game

Hi,

I'm using the Java port of JBox2D available from http://www.jbox2d.org to create a 2D motorcycle game. I haven't had many issues, but this one has been bugging me for the last few days and I can't solve it.

How things are setup
The track that the motorcycle rides on is defined as a bunch of bezier splines. This track is converted to a bunch of Body objects, each containing many box shapes (polygons shaped to form boxes) that are butted together end-to-end to roughly fit to the shape of the splines. Each box is between 1 and .01 units in width and a constant .1 units high. The rotation varies depending on the slope of the spline at a given location. The track has a friction value of 1.0, 0 restitution and 0 density.

The players motocycle is represented by 3 bodies: 2 circles for the wheels and 1 box to form the chassis. The wheels are connected to the body using Revolute Joints. These joints have no limits or motors. The wheels have a radius of 0.25 units, a density of 10 units, 0 restitution and 1.0 friction. The chassis body is 1.0 units x .5 units, with a density of 12, with no restitution or friction. The wheels are placed evenly apart with a gap of about 1 unit, underneath the chassis by about 0.6 units. (ie, the centre points of the wheels and chassis form a triangle)

World gravity is set to -9.8 on the y axis.

I've disconnected the rendering and physics using the algorithm defined the the "Fix Your Timestep" article. The world is updated at 1/60 intervals. I'm currently using 20 for my iterations, but values between 10 and 50 have made no significant difference.

Unless I'm missing something, I feel that my units all fall within the reasonable range for JBox2D.

My Problem
The main issue I'm seeing is that the wheels, when the motorcycle is moving at fairly high velocity (but not outrageous — enough to do loop the loops), bounce off the track uncontrollably, and in general slip from the pivot point of their revolute joint (so bad that sometimes the two wheels are almost touching each other).

The wheel closest to the direction of movement (ie, right-most wheel when moving x+) seems to be effected the worst. The front of the bike bounces up and down. This wheel also seems to slip against the ground, as if friction isn't effecting it.

I was originally applying torque directly to the wheels, but have also tried applyForce/Impulse to the chassis, wheels, and both at the same time to "push" the bike along. I've also tried enabling the motor on the revolute joints without much success.

The applyForce/Impulse method seems to reduce the problems I'm having, but they still occur — enough for them to be an issue.


Or am I approaching this the wrong way?

Thanks,
Adam
Just a wild guess, but, maybe enabling "isBullet" for the motor helps? It solved some collision problems I had with reasonably fast moving objects.
Here are a couple things to try:

- Use a smaller time step.
- Turn off continuous collision detection. The wheels are doing CCD with the ground, but the joints are not solved. This feature has been implemented, but it has been turned off due to some problems.
- Use a larger density for the wheels.
Also, I notice that you said the boxes are between .01 an 1 meter in width - anything below (if I remember correctly) .04 might not function correctly, particularly with CCD, because the shrunken core shape used for CCD will get pushed past the centroid. In C++ the program would actually crash, but in Java Sun decided assertions should be disabled by default so it won't, and I'm not really sure what happens if that math goes wrong... Try running your program with assertions enabled, if there's a problem it should then assert (to do this, use the -ea VM flag).

I'm not sure if that will fix your problem, but the stuff you said about the jitter sounds like it could be caused by that.
Sorry for the late reply. Been very busy with uni the last week.

Daid wrote:
Just a wild guess, but, maybe enabling "isBullet" for the motor helps? It solved some collision problems I had with reasonably fast moving objects.


Thanks for the suggestion, but unfortunately it didn't solve the issue. I didn't even think of turning on this option though, since I thought of bullets as small, high speed objects (ie, bullets from some kind of gun 😀) rather than the wheels of a bike!

Erin Catto wrote:
Here are a couple things to try:

- Use a smaller time step.
- Turn off continuous collision detection. The wheels are doing CCD with the ground, but the joints are not solved. This feature has been implemented, but it has been turned off due to some problems.
- Use a larger density for the wheels.


Did all three and it made a big improvement to the stability of the simulation! Thanks heaps.

ewjordan wrote:
Try running your program with assertions enabled, if there's a problem it should then assert (to do this, use the -ea VM flag).


Enabling assertions did reveal some cases in which my level geometry "core" size was less than .04 units, which I've now fixed. But not all of my levels exhibited this issue, so I'm not sure how related it was to my jitter problems -- it may have been worse on the levels that created invalid geometry, but the sim was so unstable that I probably wouldn't have noticed if it did have an effect. Still its good to know that I'm avoiding potential problems in the future.


Thanks for all your help guys,
Adam

Original thread: https://box2d.org/forum/viewtopic.php?t=1499