Search Unity

Question Question: Clamping Rotation to Prevent Flipping Over

Discussion in 'Visual Scripting' started by VRaptorX1, Oct 15, 2023.

  1. VRaptorX1


    Apr 11, 2016
    I'm making a car combat game in my spare time and I want the cars to go up and down ramps, in many different directions. That mean's I can't freeze the rotations...which means they can flip over. So I wanted to create a script or visual script that would prevent the cars from turning too much in the X and Z rotations.

    This is what I have thus far:
    Screen Shot 2023-10-15 at 4.17.05 AM.png
    I've tested it. It fact clamp the rotations for X and Z. I no longer flip over. I see the values going into everything.

    However an interesting conundrum has occurred in its place. Now the moment I hit the limit, the car vibrates back and forth like a lunatic. It especially hates whenever I go in reverse (as in flat surfaces cause the shakes).

    So I guess my first question is: is the code to blame? Or would this be something on the wheel colliders, mass, drag, etc?

    I tried a lot of stuff with quaternion, set rotation, etc. This is the most stable I was able to make it.

    I have another basic controller on this. Acceleration, top speed, current speed. That sort of stuff. Acceleration is an add force. Turning is a rotation. In case that matters.