Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by DanjelRicci · Mar 11, 2010 at 05:26 PM · physicsvehicle

Why is my vehicle steering on its own when I accelerate?

My vehicle in Unity has a problem: it slightly steers on the right, on its own. And it's very strange, since all the WheelColliders are perfectly alligned and propelled with the same torque value. The only difference between the wheels is that rear wheels are bigger than front ones (my vehicle is a Kart), but they are perfectly mirrored. I tried to add some kind of hardcode correction, but I removed it because the problem persised, just behaving a bit differently. I hope it's not a bug... Anyway, I attached the code that moves the kart so you can check. Also, do you think this code is slow?


//CARATTERISTICHE DEL VEICOLO /*Accelerazione*/ var maxtorque = 85.0; /*Velocit*/ var maxspeed = 1.3; /*Sterzata*/ var maxsteer = 15.0; /*Frenata*/ var brakepower = 100.0;

//VALORI DI SISTEMA /Marcia iniziale/ private var currentgear = 0; /Sterzata temporanea/ private var tempsteer = 0.0; /Moltiplicatore sterzata/ private var easysteer = 1.3; /Abbassa baricentro/ rigidbody.centerOfMass = Vector3(0,-0.3,0);

//VALORI DI MOVIMENTO /Accelerazione finale/ private var endTorque = 0.0; /Frenata finale/ private var endBrake = 0.0; /Sterzata finale/ private var endSteer = 0.0;

//DEFINISCI COLLIDER DELLE RUOTE var Coll_FrSX = transform ; var Coll_FrDX = transform ; var Coll_ReSX = transform ; var Coll_ReDX = transform ;

function FixedUpdate () {

//CAMBIA IL DRAG SE SI E' A TERRA O IN ARIA if (Coll_ReDX.collider.isGrounded == true && Coll_ReSX.collider.isGrounded == true) rigidbody.drag = 0.4; if (Coll_ReDX.collider.isGrounded == false && Coll_ReSX.collider.isGrounded == false) rigidbody.drag = 0.2;

//SISTEMA DEL CAMBIO //Vai a folle if (currentgear == 1 && Coll_ReDX.collider.rpm < 0.01 && Coll_ReDX.collider.rpm < 0.01) currentgear = 0; if (currentgear == -1 && Coll_ReDX.collider.rpm > -0.01 && Coll_ReDX.collider.rpm > -0.01) currentgear = 0; //Innesta la prima if (currentgear == 0 && Input.GetAxis("Vertical") > 0.01) currentgear = 1; //Innesta la retromarcia if (currentgear == 0 && Input.GetAxis("Vertical") < -0.01) currentgear = -1;

//CAMBIA I VALORI DI MOVIMENTO IN BASE ALLA MARCIA //Marcia avanti if (currentgear == 1) { endTorque = Mathf.Clamp(Input.GetAxis("Vertical"),0.0,1.0)maxtorque-((rigidbody.velocity.magnitude+rigidbody.velocity.magnitude)/maxspeed); endBrake = Mathf.Clamp(Input.GetAxis("Vertical"),-1.0,0.0)-brakepower; endSteer = (tempsteer-(Mathf.Clamp((rigidbody.velocity.magnitude/easysteer)/2,0.0,tempsteer-1)))*(Input.GetAxis("Horizontal")); } //Marcia indietro if (currentgear == -1) { endTorque = Mathf.Clamp(Input.GetAxis("Vertical"),-1.0,0.0)*60+(rigidbody.velocity.magnitude*7); endBrake = Mathf.Clamp(Input.GetAxis("Vertical"),0.0,1.0)*brakepower; endSteer = (tempsteer+10-(Mathf.Clamp(rigidbody.velocity.magnitude/easysteer,0.0,tempsteer-1)))*Input.GetAxis("Horizontal"); }

//Temporary code to be used before the Drifting code Coll_ReDX.collider.sidewaysFriction.stiffness = 0.12; Coll_ReSX.collider.sidewaysFriction.stiffness = 0.12; Coll_FrDX.collider.sidewaysFriction.stiffness = 0.12; Coll_FrSX.collider.sidewaysFriction.stiffness = 0.12; tempsteer=maxsteer;

//MUOVI IL VEICOLO //Accelerazione Coll_ReDX.collider.motorTorque = endTorque; Coll_ReSX.collider.motorTorque = endTorque; //Frenata Coll_ReDX.collider.brakeTorque = endBrake; Coll_ReSX.collider.brakeTorque = endBrake; //Sterzata Coll_FrDX.collider.steerAngle = endSteer; Coll_FrSX.collider.steerAngle = endSteer;

//ESCI DAL GIOCO if (Input.GetKey ("escape")) {Application.Quit();} }

//VISUALIZZA I DATI SU SCHERMO function OnGUI(){ GUI.Label(Rect(0,0,1000,1000), "Speed: "+rigidbody.velocity.magnitude.ToString()); GUI.Label(Rect(0,20,1000,1000), "Air resistance: "+rigidbody.drag.ToString()); GUI.Label(Rect(0,40,1000,1000), "Gear: "+currentgear.ToString()); GUI.Label(Rect(0,60,1000,1000), "Render time: "+Time.deltaTime); }

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

8 Replies

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

Answer by duck · Mar 11, 2010 at 07:54 PM

I've seen this crop up again and again, and unfortunately it does seem to be a bug with the way that wheelcolliders are implemented in the version of Physx which is included.

I haven't checked carefully through your code, but since I've seen people complain about this before, and I've seen it myself, I'm sure it's the bug.

I successfully made a few off-road type games where the bug wasn't apparent, but this was mainly because the terrain was quite rough and there were many bumps and jolts, so the slight pull to one side was not noticable, however it seems that the simple and cleaner your scene is, the more apparent the bug is. For example, a friend was making a forklift truck game - no suspension, no gears, and completely flat floors, and the bug was quite apparent. I think he gave up on wheelcolliders and switched to some other method of propulsion instead - as I have done with my latest car game (i.e. implemented my own wheel collider).

Let's hope this is one of the as-yet-unnamed "physics improvements" that are coming with Unity 3.

Comment
Add comment · Show 1 · 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 DanjelRicci · Mar 11, 2010 at 08:08 PM 0
Share

Thank you very much for the quick answer! Too bad it's a bug... I could use a simplier driving engine, but I'm not sure if I can do any better. Luckyly this WheelCollider sistem I managed to set up came out really good, so I think I will continue to use it. I'll just have to find someway to hide this bug (unfortunately this is not a rally game)!

avatar image
3
Best Answer

Answer by Edy · Jun 17, 2010 at 11:26 PM

It's not exactly a bug - it's the way WheelColliders work. The sideways force generated by a wheel is based on the amount of sideways slip on that wheel. This means that some slip will always be present, even a small amount. If you raise the sideways stiffness to a ridiculously high value then the effect cannot be noticed, but you get infinite grip on that wheel.

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 DanjelRicci · Jul 02, 2010 at 10:05 AM 0
Share

That's a good explation for sure. Thanks for that! ;)

avatar image Edy · Jul 03, 2010 at 03:49 PM 0
Share

$$anonymous$$y first accepted answer, hooray! I'm working on an utility class for making the WheelCollider's friction curves usable. Here you can see the results so far: http://www.edy.es/unity/offroader_v2.html I'll write a complete article on WheelCollider's friction curves as well, but they work in a way so different to expected and the available documentation is so wrong, that I still don't know where to start at :P

avatar image
1
Best Answer

Answer by HASullivan · Apr 16, 2010 at 03:36 PM

Having the same issue, so far I have tracked it down to slight variation in the rpm on the drive wheels. Some vehicles drift right, some left, and some back and forth. I have tested the order of torque application, ect and it makes no difference.

This is a wild guess, but to me it seems to be an order of execution issue inside the engine where each is looped through (in what ever order the show up in the loop) and that time is used. Only the ultra minor difference being time is not the frame start time, but the current time. It could also be a precision issue, but I would expect to see it rear its head elsewhere if that were the case.

It seems in our case we are going to have to home grow a proper wheel.

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
avatar image
1

Answer by Eugene · May 30, 2010 at 03:43 AM

I think it's probably because the centre of mass is not exactly in the centre. I know it's not because the wheels are rotating at different speeds because I had this problem with my bike sim and that only uses two wheels. The problem seems to have been fixed by moving the centre of gravity according to the angle of the bike.

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 DanjelRicci · Jun 03, 2010 at 02:09 PM 0
Share

It doesn't seem to be a problem of centre of mass, because I set up the CO$$anonymous$$ to be perfectly at the centre of the vehicle...

avatar image Runalotski · Apr 20, 2014 at 02:08 AM 0
Share

hello im new to unity and have had the same problem messing around with it i think that the wheel collider may be conflictiong with collisions in the vehical itsself or something

as when i make the wheel colliders stick out of the modle (yes the car floats abit with this setup) its drive perfectly straight. probably should tick off the cilliders or change the to triggers.

hopefully this is helpful to someone.

avatar image
0

Answer by GODLIKE · May 30, 2010 at 09:21 AM

I don't know how but the car of this guy goes straight.

http://forum.unity3d.com/viewtopic.php?t=52133

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
  • 1
  • 2
  • ›

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Vehicle physics 2 Answers

Implement a vehicle that can "turn on the spot". 3 Answers

Creating a magnetic vehicle (like F-Zero) (2) 1 Answer

Unity 5 - good parameters for vehicle 1 Answer

Hover vehicle in a tunnel 1 Answer


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