wheel collider / script offsets the meshes
Hi.
I try to create a simple racing game and I'm a beginner in C# programming and Unity user.
So there is a simple car I modeled and its wheels are separate objects. The colliders have also their own objects.
The code so far:
WheelCollider wCollider;
public Transform tMesh;
public float torque = 20f;
// Start is called before the first frame update
void Start()
{
wCollider = GetComponent<WheelCollider>();
}
// Update is called once per frame
void Update()
{
Quaternion quatWheelCollider;
Vector3 v3WheelColliderPos;
float fInputVert = Input.GetAxis("Vertical");
wCollider.GetWorldPose(out v3WheelColliderPos, out quatWheelCollider);
tMesh.position = v3WheelColliderPos;
tMesh.rotation = quatWheelCollider;
drive(fInputVert);
}
void drive(float accel)
{
accel = Mathf.Clamp(accel, -1, 1);
float thrustTorque = accel * torque;
wCollider.motorTorque = thrustTorque;
}
The only thing Im doing is using motorTorque to drive the car (line 30). And the meshes are aligned with the colliders with simple code (line 19 and 20)
I also tried to simply set the meshes as child objects of the colldiers but that doesn't work at all. that's that thing Im confused with cause the code does exactly that or am I wrong?
but for some reason the right wheels are moved to the side:
I don't know why it's happening. The colldiers don't have any weird offset or anything like that.
also the hierarchy:
I hope someone can help me :)
Your answer
Follow this Question
Related Questions
WheelCollider RPM values all over the place, how can I get more even values? 0 Answers
Whats wrong with my car auto park AI scripts?,What am I missing from my car auto park code? 0 Answers
Make the car stop by hitting the wall 1 Answer
How to teleport a car? 1 Answer
How would I change material properties of a box collider via script? 0 Answers