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
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