how do i get the y-transform from the wheel colliders and apply this to the geometry?
when i use suspension the wheel geometry does not follow, i have tried getting the transform.localposition
from the wheel colliders but it turns out this does not change, even when the wheel moves along the y-axis due to suspension.
i have heard of "GetGroundHit’ and have been trying for the last hour the get a value out of this and apply it to the wheel geometry and have not succeeded.
any help would be appreciated (i am a C# person)
just hand over the chocolate and no-one gets hurt
EDIT, just realized the title might not make much sense, should be:
How to get Y-position from wheel collier suspension and apply this to wheel geometry
Found this on some random website, if anyone else has this problem just attach this code to your wheel geometry
and assign the wheel collider as the variable.
using UnityEngine;
using System.Collections;
// ADD THIS SCRIPT TO EACH OF THE WHEEL MESHES / WHEEL MESH CONTAINER OBJECTS
public class Wheel : MonoBehaviour {
public WheelCollider wheelC;
private Vector3 wheelCCenter;
private RaycastHit hit;
// Initialization
void Start () {
}
// Display
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);
}
}
// Physics
void FixedUpdate() {
}
}