Hi! I have a car with wheel colliders and wheel meshes as separate gameobjects.
Each fixed update, I set the mesh transform to match the wheel collider position and rotation.
void FixedUpdate()
{
for (int count = 0; count < allWheelMeshes.Length; count++)
{
Transform mesh = allWheelMeshes[count];
WheelCollider wheelCollider = allWheelColliders[count];
wheelCollider.GetWorldPose(out Vector3 wheelPosition, out Quaternion wheelRotation);
mesh.position = wheelPosition;
mesh.rotation = wheelRotation;
}
}
However, I want to set the local Y rotation of the mesh transform to 0 afterward so that it points straight and doesn’t rotate due to the steeringAngle on the wheelCollider. Simply doing mesh.localRotation = Quaternion.Euler(mesh.localEulerAngles.x, 0f, mesh.localEulerAngles.z);
after setting the mesh rotation as the wheel rotation can sometimes show a local Y rotation of 180 instead of 0 as the wheel rotates, which makes the wheel rotate in the wrong direction. I would expect the rotation to always be 0. Why is this?
Example - see local Y position of mesh transform going from 0 to 180 and the direction changing.