So I am trying to implement a car controller script in Unity were the WheelTransform
position and rotation is set with every update as the same as the WheelCollider
position and rotation, it all works fine except for one thing: when translating the WheelTransform
, if the car goes slowly, WheelTransform
translates as expected, but when the car goes faster, there's a clear offset between the WheelTransform
position and the actual position of WheelCollider
. Here's the code were WheelTransform
position and rotation is set as the same as the WheelCollider
position and rotation:
private void UpdateWheels()
{
UpdateWheelPos(frontLeftWheelCollider, frontLeftWheelTransform);
UpdateWheelPos(frontRightWheelCollider, frontRightWheelTransform);
UpdateWheelPos(rearLeftWheelCollider, rearLeftWheelTransform);
UpdateWheelPos(rearRightWheelCollider, rearRightWheelTransform);
}
private void UpdateWheelPos(WheelCollider wheelCollider, Transform trans)
{
Vector3 pos;
Quaternion rot;
wheelCollider.GetWorldPose(out pos, out rot);
trans.rotation = rot;
trans.position = pos;
}
Every single one of the car controller scripts I've found and tried use the same code for this section, I have also tried with 2d sprites without any colliders as WheelTransform
but neither the scripts or changing WheelTransform
solved the problem. Thanks in advance for the help.
UpdateWheels()
from anUpdate()
function? Try calling it fromLateUpdate()
instead. \$\endgroup\$