Unity tutorial: How to stop a rigid body from oscillating, vibrating, and shaking

This week I've spent a few hours of my life building a realistic boat simulator in Unity. Adding forces and all the complicated math and physics needed was actually relatively easy. But when I added all the forces to my boat, which had a rigid body attached to it, the boat began to oscillate, shake, and vibrate like crazy back and forth.
The first solution I had was to increase the angular drag to something like 50. But this was supposed to be a realistic boat simulator, so increasing the angular drag would make it less realistic. For example, the boat couldn't tilt over with that high angular drag. An unsinkable boat is not realistic.
The next idea I had was to look through all physics book and half of Google to find a better solution. One solution I found in the book Physics for Game Developers was something called roll period and pitch period, but that didn't work either.
Finally I found a single line of code that solved the problem. It is maxAngularVelocity, and you change it to something like this to stop the oscillations, vibrations, and shaking:

boatRB.maxAngularVelocity = 0.5f;

...where boatRB is your rigid body. The final result looks like this:


Tomorrow I will probably write a longer tutorial on how to make a realistic boat simulator in Unity.

Comments

  1. The first solution you had was to increase the angular drag to something like 50. But this was supposed to be a realistic boat simulator, so increasing the angular drag would make it less realistic. Thanks for share.

    ReplyDelete
  2. increase the bounce threshold in Edit > project settings > physics > bounce-threshold to something like 8

    ReplyDelete

Post a Comment