• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by slkjdfv · Jul 03, 2010 at 11:05 PM · physicscar

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image spinaljack · Jul 04, 2010 at 10:35 AM 0
Share

Just lower the car's centre of mass dynamically as you turn and go faster

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tetrad · Jul 06, 2010 at 12:20 AM 0
Share

Why not just put it here since there is no P$$anonymous$$ system on answers.

avatar image slkjdfv · Jul 06, 2010 at 01:01 AM 0
Share

i thought there was lol heres the link my bad ^^. http://www.edy.es/unity/offroader.html the script is at the bottom.

avatar image
0

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);  
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Apr 21, 2013 at 05:21 PM 1
Share

The javascript version is incorrect.

avatar image fafase · Apr 21, 2013 at 05:30 PM 0
Share

And here is the original http://forum.unity3d.com/threads/50643-How-to-make-a-physically-real-stable-car-with-WheelColliders

avatar image parsa_dragon93 · May 15, 2013 at 07:50 AM 0
Share

sry didn't have time to test it :)

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Endless Runner Car Physics Issues (Again) 1 Answer

Cant seem to make this basic 3D car turn properly 0 Answers

Braketorque makes car behave like a kinematic rigidbody 0 Answers

Wheel Collider - Mesh/Box Collider Problem 0 Answers

Car turn back after release button 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges