Hey! I’m working on a racing game atm but this issue has me really stuck.
I am currently still new to Unity and the community so please tell me if I’m not providing enough info for the problem. Any feedback would be appreciated…
The code below is supposed to make the wheel spin based on the velocity and also rotate side to side based on the steering angle.
The wheel spin and the wheel steering works as intended but the problem is, the wheel seems to have its z axis flipped every 360 degree rotation in the x axis.
I don’t understand why this is the case.
private void Update()
{
transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, steerAngle, transform.localRotation.eulerAngles.z);
wheelxRotation = Vector3.Dot(rb.GetPointVelocity(wheelMesh.transform.position), transform.forward) * Time.deltaTime / wheelCircumference * 360;
Quaternion steerRotation = Quaternion.Euler(wheelMesh.transform.localRotation.eulerAngles.x, steerAngle, wheelMesh.transform.localRotation.eulerAngles.z);
wheelMesh.transform.localRotation = steerRotation;
wheelMesh.transform.Rotate(-Vector3.right, wheelxRotation);
Debug.Log(wheelMesh.transform.localEulerAngles);
}
Below are the images of the car and the local euler angles of the wheel at that point.
As you can see, the wheel seems to have flipped despite not changing the local z axis.
This flip occurs every 360 degree rotation of the wheel (as it spins).
