I have researched some examples of anti roll bars for Unity but they are all for unity 4 and bellow so they do not work in unity 5. Can someone please assist me in making an anti roll bar script in C# for Unity 5?
Here is the best example I could find (I don't know how to convert it for unity 5):
using System.Collections;
public class AntiRollBar : MonoBehaviour {
var WheelL : WheelCollider;
var WheelR : WheelCollider;
var AntiRoll = 5000.0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void fixedUpdate () {
var hit : WheelHit;
var travelL = 1.0;
var travelR = 1.0;
var groundedL = WheelL.GetGroundHit(hit);
if (groundedL)
travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;
var groundedR = WheelR.GetGroundHit(hit);
if (groundedR)
travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;
var antiRollForce = (travelL - travelR) * AntiRoll;
if (groundedL)
rigidbody.AddForceAtPosition(WheelL.transform.up * -antiRollForce,
WheelL.transform.position);
if (groundedR)
rigidbody.AddForceAtPosition(WheelR.transform.up * antiRollForce,
WheelR.transform.position);
}
}
FixedUpdate(), but you callfixedUpdate(), instead. \$\endgroup\$