- Home /
my car keeps fliping over i have an idea how to fix it but i need help
I want to add anti-roll bars to my car to keep it from flipping. how would i do this? if you dont know what an anti-roll bar is heres a description.
Stabilizer bars (A.K.A. anti-roll bars) "connect" the two wheels of the same axle allowing a limited degree of freedom between the two. When one of the wheels is pushed upwards, the stabilizer bar transfers a portion of that compression force to the other wheel, so its suspension compress as well. This limits the roll of the body's car at that axle thus keeping it from flipping.
Just lower the car's centre of mass dynamically as you turn and go faster
Answer by slkjdfv · Jul 05, 2010 at 11:50 PM
I found a script that simulates anti roll bars :D. if u want a link to the web page pm me.
Why not just put it here since there is no P$$anonymous$$ system on answers.
i thought there was lol heres the link my bad ^^. http://www.edy.es/unity/offroader.html the script is at the bottom.
Answer by parsa_dragon93 · Apr 21, 2013 at 05:19 PM
the script is really simple
in Javascript :
public class AntiRollBar : MonoBehaviour
{
public WheelCollider WheelL;
public WheelCollider WheelR;
public float AntiRoll = 5000.0f;
public void FixedUpdate()
{
WheelHit hit;
float travelL = 1.0f;
float travelR = 1.0f;
bool groundedL = WheelL.GetGroundHit(out hit);
if (groundedL)
travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;
bool groundedR = WheelR.GetGroundHit(out hit);
if (groundedR)
travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;
float 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);
}
}
in C#
using UnityEngine;
using System.Collections;
public class AntiRollBar : MonoBehaviour {
public WheelCollider wheelL;
public WheelCollider wheelR;
public float antiRollVal = 5000f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
WheelHit hit;
float travelL=1.0f;
float travelR=1.0f;
bool groundedL = wheelL.GetGroundHit(out hit);
if (groundedL){
travelL = (-wheelL.transform.InverseTransformPoint(hit.point).y - wheelL.radius) / wheelL.suspensionDistance;
}
bool groundedR = wheelR.GetGroundHit(out hit);
if (groundedR){
travelR = (-wheelR.transform.InverseTransformPoint(hit.point).y - wheelR.radius) / wheelR.suspensionDistance;
}
float antiRollForce = (travelL - travelR) * antiRollVal;
if (groundedL)
rigidbody.AddForceAtPosition(wheelL.transform.up * -antiRollForce,
wheelL.transform.position);
if (groundedR)
rigidbody.AddForceAtPosition(wheelR.transform.up * antiRollForce,
wheelR.transform.position);
}
}
Answer by mahdiii · Oct 29, 2016 at 06:07 PM
I think it is better to execute both that rigidbody.AddForceAtPosition(wheelL.transform.up -antiRollForce, wheelL.transform.position);
rigidbody.AddForceAtPosition(wheelR.transform.up antiRollForce, wheelR.transform.position);
when either groundedR or groundedL are true because when one wheel is on the ground and one not only one condition is executed.
Your answer
Follow this Question
Related Questions
need tutorials for rigidbody.Addforce 1 Answer
Car Tire Issues 2 Answers
Car - WheelCollider - Why the side is getting up? 2 Answers
Raycast Car Physics 0 Answers
2D 360 degress platformer example needed 0 Answers