Applying Separate Rotations

Does anyone understand why these rotations when used together are not producing the same results?
When run independently they work as intended but when both of them are uncommented the front steer tires produce erratic rotations.

    void TireVisuals()
    {
        //Steer Front Tires
        foreach (Transform FM in TurnTires)
        {
            //This code works as intended
            //FM.localRotation = Quaternion.Slerp(FM.localRotation, Quaternion.Euler(FM.localRotation.eulerAngles.x, input.rudder * steerAngle, FM.localRotation.eulerAngles.z), 0.2f );
            
        }

        //Tire mesh rotate
        foreach (Transform mesh in TireMeshes)
        {
            //This code works as intended
                //mesh.transform.RotateAround(mesh.transform.position, mesh.transform.right, speed / 3); 
          
          
        }
    }

I wouldn’t slerp the Quaternion when you only want the Y angle to change.

Instead just control the steering angle so the angle smoothly changes, then drive the .localRotation directly like this:

FM.localRotation = Quaternion.Euler( 0, currentSteeringAngle, 0);

(And then obviously repeat for the rotation of the tire itself).

The rotation of the tire should be on a separate transform from the steering. You COULD combine them but … complications!

Smoothing movement between any two particular values:

You have currentQuantity and desiredQuantity.

  • only set desiredQuantity
  • the code always moves currentQuantity towards desiredQuantity
  • read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: SmoothMovement.cs · GitHub

2 Likes

Thanks that worked for me.

1 Like