Created
February 11, 2015 17:11
-
-
Save victorbstan/4dde0d0b4203c248423e to your computer and use it in GitHub Desktop.
C# Unity suspension example script for wheel meshes to follow wheel collider suspensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment