So I’m getting the hang of making vehicles generally now I think but one thing that’s been frustrating lately is getting the wheels to turn with the colliders. I’m looking up various options and this one I found on this topic seemed to be the most easy to understand but despite following the instructions posted nothing seems to have happened.
using UnityEngine;
using System.Collections;
public class wheel : MonoBehaviour {
public WheelCollider wheelC;
private Vector3 wheelCCenter;
private RaycastHit hit;
void Start () {
}
void Update () {
wheelCCenter = wheelC.transform.TransformPoint(wheelC.center);
if ( Physics.Raycast(wheelCCenter, -wheelC.transform.up, out hit, wheelC.suspensionDistance + wheelC.radius) ) {
transform.position = hit.point + (wheelC.transform.up * wheelC.radius);
} else {
transform.position = wheelCCenter - (wheelC.transform.up * wheelC.suspensionDistance);
}
}
}
Now one thing that was mentioned that the person who posted this code is suggesting is that he had empty gameobjects which I haven’t tried yet, I’ll give it a shot and see what happens but I don’t have a clue as to why my meshes aren’t rotating.
If putting the script on an empty gameobject doesn’t work, It’d be great if someone could help me with this particular bit of code. Or perhaps I should just take a look at the other code out there and try them out instead?
I’ve also noticed something very unusual thanks to this code! it seems that my front wheels are rotating one way and my back wheels the other which might explain why I’ve been having tons of stability problems.