- Home /
Vehicle issues.
Hello! I am trying to make a car. all works well. wheels turn, suspension suspends, springs spring, but like this smart fellow mentioned The car will just tip as soon as some speed is gained and a turn is attempted. This is the exact issue I'm having.
The script I'm using is a transcription from JS to C# and it goes a little something (100% exactly) like this:
using UnityEngine;
using System.Collections;
public class AntiFlip: MonoBehaviour {
public WheelCollider WheelL;
public WheelCollider WheelR;
public float TraverL = 1;
public float TravelR = 1;
public float AntiRollStrength;
public void Update () {
WheelHit hit;
bool GroundedLeft = WheelL.GetGroundHit (out hit);
if (GroundedLeft) {
TraverL = ((-WheelL.transform.InverseTransformPoint (hit.point).y - WheelL.radius) / WheelL.suspensionDistance);
}
bool GroundedRight = WheelL.GetGroundHit (out hit);
if (GroundedRight) {
TravelR = ((-WheelR.transform.InverseTransformPoint (hit.point).y - WheelR.radius) / WheelR.suspensionDistance);
}
float AntiRollForce = (TraverL + TravelR) * AntiRollStrength;
if (GroundedLeft) {
GetComponent<Rigidbody> ().AddForceAtPosition (WheelL.transform.up * -AntiRollForce, WheelL.transform.position);
}
if (GroundedRight) {
GetComponent<Rigidbody> ().AddForceAtPosition (WheelR.transform.up * AntiRollForce, WheelR.transform.position);
}
}
}
I actually joined Unity to try to make my own car game (me an my dad are car fanatics, but i'm a little more nerdy so...) I'll be pretty dissapointed if I cant make it work.
If any more details are needed to help people help me, just ask away in the comments (AND NOT AS AN ANSWER (unless is a question answer))
PS. did have it go fast and not tip, but the slip value was over 5 so... driving on ice =/= fun.
PPS: using WheelColliders and C# (if that wasn't clear).
Your answer
Follow this Question
Related Questions
C# WheelHit.force display wheel suspensions on meshes 0 Answers
Wheel cutting through other objects 0 Answers
Car wheels not stopping when I brake 0 Answers
How do I Instantly stop wheels (WheelCollider) from moving ? 0 Answers
Best way to make wheels freely turn / swivel? (Like a shopping cart) 2 Answers