I’m having a bit of an issue I can’t seem to resolve no matter what I do. The wheels are rotating locally as they should be (to make it appear the wheels are turning as the car accelerates). I am observing the transforms for the wheels with the issue and noticing every so many frames they are getting a 180- degree rotation in the Z axis. Basically as I accelerate they seem to be “flipping” around the Z axis. I have a hunch it’s this line of code
the variable aRight is a Vector3 “var aRight : Vector3;”
private var rotateAmount : Vector3;
function updateWheels()
{
// front wheels need rotating on their y axis too, for steering
wheelT[0].localEulerAngles.y = horizontal * 30;
wheelT[2].localEulerAngles.y = horizontal * 30;
rotateAmount = aRight * (relativeVelocity.z * 1.7 * Time.deltaTime * Mathf.Rad2Deg);
wheelT[0].Rotate(rotateAmount);
wheelT[1].Rotate(rotateAmount);
wheelT[2].Rotate(rotateAmount);
wheelT[3].Rotate(rotateAmount);
}
SOLVED: Well I solved this issue and it’s not too hackish. Basically I realized the Euler Angle calculations for the steering effect (wheels turning around Y axis) was conflicting with the Rotate that was making the wheels rotate around X axis based on kart speed. I created parent gameobject transforms for the two front wheels, exposed them as public assignable variables and then just separated out the Euler Angle calculations on those parent transforms. Seems this separation worked like a charm. So my script function ended up smaller and like this:
"function updateWheels()
{
// front wheels need rotating based on speed
wheelT[0].transform.Rotate( relativeVelocity.z * 2, 0, 0);
wheelT[1].transform.Rotate( relativeVelocity.z * 2, 0, 0);
wheelT[2].transform.Rotate( relativeVelocity.z * 2, 0, 0);
wheelT[3].transform.Rotate( relativeVelocity.z * 2, 0, 0);
// front wheels need rotating on their y axis too, for steering
LFWheelTransform.localEulerAngles.y = horizontal * 40;
RFWheelTransform.localEulerAngles.y = horizontal * 40;
}
I believe it would be better to cache the transforms themselves , perhaps in a different list or array or fields whatever to avoid this look up 4 times per frame per car.