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:
The problem is the choice of integer values for lanes. They can only either be lane 0, 1 or 2. They can’t be in between round numbers. It needs to be a floating point value so that it can be between lanes.
This type of question comes up so universally I have finally just made a sample package to demonstrate the basic concept. Read my first post above and see if you can correlate each part of the code to the steps indicated.
Code located here: SmoothMovement.cs · GitHub
6430100–719246–SmoothMo…
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
Kurt-Dekker:
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:
https://discussions.unity.com/t/812925/5
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: https://gist.github.com/kurtdekker/fb3c33ec6911a1d9bfcb23e9f62adac4
Thanks that worked for me.
1 Like