Vehicle physics tweaking help

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
sturm
Posts: 3
Joined: Sat Sep 13, 2008 8:34 pm

Vehicle physics tweaking help

Post by sturm »

Hi,

Ive been using BepuPhysics for a few days with my XNA port of Need for Speed 1 (it uses the tracks, models and art from NFS1, but the engine is in XNA). BepuPhysics has been nice and easy to integrate compared to JigLib or PhysX. :)

I am having a few issues tweaking the Vehicle/Wheel physics models to get the right behaviour. I'll just list a couple of issues I have and what Ive tried to get around them.


Problem: Car too tail-happy, will spin completely out of control with little provocation

Tried: Shortened, firmed suspension, set centerOfMassOffset forward (this helped, but meant that the car sometimes nose-dived into the ground around corners). Increased angular damping (this only helped at high values which stopped the steering working correctly). I also tried adjusting the slideFriction on the back wheels, had some effect but not enough to prevent spinouts.
Also tried just accelerating the front wheels only - no noticeable effect.


Problem: Car floats too much over jumps

Tried: Upping the simulationSettings.gravity to -25 instead of -9.8. This made the car behave realistically in the air, but pushed the car down to the ground. I couldn't find a value on the suspension that would firm it up enough to hold the body up.


Problem: Cant change the wheel size

Tried: Changing the .375 wheelSize in the demo - the car behaves strangely but the wheel.WorldMatrix doesnt change scale.


Basically what I'm after at this stage is some tips for a 'safe' vehicle model - one that might be boring, but doesnt slide out all the time. I can post code samples or a demo if that makes it easier.

thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Vehicle physics tweaking help

Post by Norbo »

Thanks for trying it out!

Increasing the friction to very high values can provide an arcadey feel. A center of mass offset down the y axis can help keep the car from rolling during sharp turns. Altering the mass distribution can also help- in the demos, removing all the mass from the upper block can reduce spinouts a bit. Moving it forward would have a similar or more pronounced effect. The local inertia tensor can be computed manually, though it is usually easier just to move subbodies around until it feels right. If necessary, you can put a heavy subbody hidden inside the car's body to adjust its mass distribution.

The floaty appearance could be caused by the size of the car's body; shrinking it down to a real life scale would match real life gravity better. The wheels also have a maxSuspensionForce parameter (second from the last) which caps the force applicable by the suspension. With a value of 500 (like in the demos), high gravity will overwhelm the suspension regardless of the spring constant.

The wheel radius is a purely cosmetic detail used to determine its angular velocity and has no effect on the world matrix's scaling. If you want to actually change the size of the wheel, change the entity representing the wheel. You can see in the demos that there are cylinders created and passed into the ConvexCastWheels- changing the cylinders' radii would adjust the wheel's function.
sturm
Posts: 3
Joined: Sat Sep 13, 2008 8:34 pm

Re: Vehicle physics tweaking help

Post by sturm »

Thanks, will try your suggestions out tomorrow :)
sturm
Posts: 3
Joined: Sat Sep 13, 2008 8:34 pm

Re: Vehicle physics tweaking help

Post by sturm »

Thanks for the suggestions. I changed the fricton/grip/etc values too much too quickly, the first time, so ended up fighting myself. This time it has worked much better, and the car is in control most of the time :)

One problem im still having is the car losing its line around slightly bumpy corners. (By slightly, I mean very slightly).

The car starts bouncing around and the front wheels lose friction. Whats the best way to combat this? Would larger wheels (im using ConvexCastWheel) even out the bumps a bit? More vehicle mass/gravity? Longer wheelbase?

I hope to have a demo out this week that should bring back some great memories of NFS1 :)

thanks for the help!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Vehicle physics tweaking help

Post by Norbo »

The most direct solution would be softening the suspension a bit. The previous 'floaty' problem can become more noticeable in this situation too, so having a realistic gravity for the size would indeed help. You might try scaling the localInertiaTensorInverse too. To take a rather extreme example, using a factor of .2 will significantlly increase the force it takes to achieve the same angular velocity, which lessens the angular bounciness. It's not a perfect solution, though.

If you want to be a little more targeted, you can scale the individual components that correspond to the X and Z local axes of the object. This makes the object require more force to rotate around those axes (so you can still steer easily). In the demos' VehicleInput class, you can see I already scale the Z axis by .5 to require more force to roll the car.

The X and Z axes in the inertia tensor correspond to elements of the first row (M1X) and the third row (M3X). Technically, the 4th element in each row doesn't need to be scaled (the inertia tensor is a 3x3 matrix stored within the 4x4 XNA Framework matrix).

There's another property in Entity called localSpaceInertiaTensor as well. This is the uninverted tensor, so you could scale its rows by 5 (instead of the .2 you'd equivalently use to scale the localInertiaTensorInverse). The field will automatically update the localInertiaTensorInverse, but changing the localInertiaTensorInverse does not update the localSpaceInertiaTensor. I'm not really fond of this strange state of affairs, so this may be changed in a future version.
Post Reply