• 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 Gameart1235 · Jan 23, 2015 at 12:18 PM · cardrivingdrive

Car Question

So I made a car that as 4 wheel Collider and the two front wheel turn the car w$$anonymous$$le the back wheel move the car. The little problem I'm having is the car flip over really easy. is there anyway i can make it so the car can't flip over.

Plz help.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KillMobil · Jan 23, 2015 at 12:47 PM

Its somet$$anonymous$$ng i've battle with a lot!

To begin with you have to really play around with the wheel collider settings to find the balance primarily on the driving sensation you want and also with the mass & scale of the ve$$anonymous$$cle.

in order to make the adjustments faster i had made a script where you can add all the wheels collider and adjust the setting with sliders. with a Debug toggle that will stop adjusting the setting on every frame. (ive put the code at End).

Now other tricks you can do to reduce flipping are:

  • Reduce the center of mass in the rigidbody EX: myRigid.centerOfMass = new Vector3 (myRigid.centerOfMass.x, centerOfMass, myRigid.centerOfMass.z);

  • Depending on the velocity of the car start applying some vertical force to the rigidbody that will push it to the ground EX:`myRigid.AddForce (new Vector3 (0, -pushDownForce, 0));`

  • Lastly w$$anonymous$$le researc$$anonymous$$ng t$$anonymous$$s at a tutorials i have found a little JS script that basically works as an antiroll bar that was quite usefull. i dont remember who wrote it... i hope its ok that i am passing the code like that!-) Antiroll_Bar.js:

        var WheelL : WheelCollider;
         var WheelR : WheelCollider;
         var AntiRoll = 5000.0;
         
         function FixedUpdate ()
             {
             var $$anonymous$$t : WheelHit;
             var travelL = 1.0;
             var travelR = 1.0;
         
             var groundedL = WheelL.GetGroundHit($$anonymous$$t);
             if (groundedL)
                 travelL = (-WheelL.transform.InverseTransformPoint($$anonymous$$t.point).y - WheelL.radius) / WheelL.suspensionDistance;
         
             var groundedR = WheelR.GetGroundHit($$anonymous$$t);
             if (groundedR)
                 travelR = (-WheelR.transform.InverseTransformPoint($$anonymous$$t.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);    
             }
     
    
    

Here the code for the WhellCollider settings :

 using UnityEngine;
 using System.Collections;
 [System.Serializable]
 public class WheelSettingCS : MonoBehaviour
 {
 
         public WheelCollider[] wheelColliders;
 
         public bool debugMode = false;
 
         [Range(0 , 10)]
         public float
                 mass = 1;
 
         [Range(0 , 2)]
         public float
                 distance = 0.2f;
 
         [Range(0 , 10000)]
         public float
                 spingVal = 5500f;
 
         [Range(0 , 100)]
         public float
                 spingDamper = 50f;
 
         [Range(-100 , 100)]
         public float
                 position = 0;
 
         [Range(0 , 5)]
         public float
                 ffextremumSlip = 1;
 
         [Range(0 , 40000)]
         public float
                 ffextremumValue = 20000;
 
         [Range(0 , 4)]
         public float
                 ffeasymptoteSlip = 2;
 
         [Range(0 , 20000)]
         public float
                 ffasymptoteValue = 10000;
 
         [Range(0 , 1)]
         public float
                 ffstiffness = 0.092f;
 
         [Range(0 , 5)]
         public float
                 sfextremumSlip = 1;
 
         [Range(0 , 40000)]
         public float
                 sfextremumValue = 20000;
 
         [Range(0 , 4)]
         public float
                 sfeasymptoteSlip = 2;
 
         [Range(0 , 20000)]
         public float
                 sfasymptoteValue = 10000;
 
         [Range(0 , 1)]
         public float
                 sfstiffness = 0.092f; 
 
 
         // Use t$$anonymous$$s for initialization
         void OnEnable ()
         {
                 FixSpringSettings ();
         }
     
         // Update is called once per frame
         void FixedUpdate ()
         {
                 if (debugMode)
                         FixSpringSettings ();
         }
 
 
         void FixSpringSettings ()
         {
                 for (int i = 0; i < wheelColliders.Length; i++) {
             
                         WheelCollider whellCol = wheelColliders [i];
                         whellCol.suspensionDistance = distance;
                         whellCol.mass = mass;
 
                         JointSpring newSuspesion = new JointSpring ();
                         newSuspesion.spring = spingVal;
                         newSuspesion.damper = spingDamper;
                         newSuspesion.targetPosition = position; 
                         whellCol.suspensionSpring = newSuspesion;
 
                         WheelFrictionCurve newFwdFriction = new WheelFrictionCurve ();
                         newFwdFriction.extremumSlip = ffextremumSlip;
                         newFwdFriction.extremumValue = ffextremumValue;
                         newFwdFriction.asymptoteSlip = ffeasymptoteSlip;
                         newFwdFriction.asymptoteValue = ffasymptoteValue;
                         newFwdFriction.stiffness = ffstiffness;
                         whellCol.forwardFriction = newFwdFriction;
                                             
                         WheelFrictionCurve newSideFriction = new WheelFrictionCurve ();
                         newSideFriction.extremumSlip = sfextremumSlip;
                         newSideFriction.extremumValue = sfextremumValue;
                         newSideFriction.asymptoteSlip = sfeasymptoteSlip;
                         newSideFriction.asymptoteValue = sfasymptoteValue;
                         newSideFriction.stiffness = sfstiffness;
                         whellCol.sidewaysFriction = newSideFriction;
 
             
                 }
 
         }
 
 }
 
 
 





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 Gameart1235 · Jan 24, 2015 at 12:34 AM 0
Share

Thank you, this was really helpful.

avatar image KillMobil · Jan 24, 2015 at 01:24 PM 0
Share

No problem m8!

avatar image
0

Answer by HarshadK · Jan 23, 2015 at 01:19 PM

Read t$$anonymous$$s forum page about How to make a physically real, stable car using WheelColliders has really good information on how to make a physically stable car.

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I do Flexible curved car or car on curved force in Unity 5? 0 Answers

Car exhaust Flame in unity 1 Answer

How to create car suspension system? 1 Answer

Good AI for vehicles 3 Answers

How to make a steering wheel that rotates when wheels do? 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