Question by
$$anonymous$$ · Jun 06, 2017 at 10:03 AM ·
rotationquaternionwheelcollidercylinder
Making visual wheel rotate together with wheel collider
Hello, I was following WheelCollider Tutorial in Unity documentation and I'm kinda stuck at making the visual wheel rotate correctly. Here's my code:
public void ApplyLocalPositionToVisuals(WheelCollider collider)
{
if (collider.transform.childCount == 0)
return;
Transform visualWheel = collider.transform.GetChild(0);
Vector3 position;
Quaternion rotation;
collider.GetWorldPose(out position, out rotation);
visualWheel.transform.position = position;
visualWheel.transform.rotation = rotation;
}
In the editor view my wheel looks like this:
however, when I enter the game view and rotation gets applied it looks like this:
Here's what my visualWheel setup:
Comment
Answer by Tathagat · Oct 17, 2017 at 01:49 PM
The script works fine, use an actual mesh instead of using a cylinder. The problem here is that you have already rotated it by 90 degrees on the Z axis.