Hi
Im having problems with the wheel coliders I have created for the tires I have. I have wheel colliders on all four tires and have a script that allows me to move the car but when I press play the front wheels turn right and the back wheels seperate from where they are meant to be.
Im not sure if it has anything to do with the box coliders I have set up on the car.
This is the code I have that makes the car move.
using System.Collections;
using UnityEngine;
public class Car : MonoBehaviour
{
public float maxTorque = 50f;
public WheelCollider[] wheelColliders = new WheelCollider[4];
public Transform[] tireMeshes = new Transform[4];
void Update()
{
UpdateMeshesPositions();
}
void FixedUpdate()
{
float steer = Input.GetAxis ("Horizontal");
float accelrate = Input.GetAxis ("Vertical");
float finalAngle = steer * 45f;
wheelColliders [0].steerAngle = finalAngle;
wheelColliders [1].steerAngle = finalAngle;
for (int i = 0; i < 4; i++)
{
wheelColliders[i].motorTorque = accelrate * maxTorque;
}
}
void UpdateMeshesPositions()
{
for(int i = 0; i < 4; i++)
{
Quaternion quat;
Vector3 pos;
wheelColliders[i].GetWorldPose(out pos, out quat);
tireMeshes[i].position = pos;
tireMeshes[i].rotation = quat;
}
}
}
I am stumped as to why this is doing it cause all the wheels are set to 0 on the z axis same with all the wheel coliders. plus I have also tried siing them up and down to see if that makes any difference.




