Search Unity

Me attempting to achieve some semi realistic vehicle physics, with wheel colliders.

Discussion in 'Made With Unity' started by Ravel, May 5, 2011.

  1. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Hello there, i was messing around with unitys wheel collider for a week now. Wher ever i read, mostly i get bad feedback about wheel colliders, but i think that physx wheel colliders are actually pretty good, they only need a little extra script for dynamic friction (i also started a thread in the scripting section, to see how many people know various methods for dynamic friction, but without succsess).

    So what i did here, is i took Andrews car tutorial (http://www.gotow.net/andrew/blog/?page_id=78, thank you!)
    and started tweaking it, switched the original track to a custom terrain one, added differential ratio, few visual effects(projector, light flares etc.), some simplyfied scripts to change friction suspension easly in one inspector and finally i also added antirollbars from edy's tutorial.
    Oh yes i was also busy updating the real script, so i did not update the ai one, so the waypoints exist and the script is also there but its "outdated"...


    So at wheel friction part, i tryed to use as lifelike values as possible, and i hope that unity/physx reads them also that way.
    Heres what i use for longitudinal lateral friction curves:
    Code (csharp):
    1.  
    2. var ForwardExtremumSlip : float = 10;//slip ratio where the tire grips at most;
    3. var ForwardExtremumValue : float = 100;//100% of the available friction is used;
    4. var ForwardAsymptoteSlip : float = 100;//slip ratio where the curve has no grip;
    5. var ForwardAsymptoteValue : float = 0;//0% of the friction available is used;
    6. var ForwardStiffness : float = 1.0;
    7.  
    8. var SidewaysExtremumSlip : float = 6;//slip angle where the tire grips at most;
    9. var SidewaysExtremumValue : float = 100;//100% of the available friction is used;
    10. var SidewaysAsymptoteSlip : float = 40;//slip angle where the curve has minimal grip;
    11. var SidewaysAsymptoteValue : float = 1;//1% of the available friction is used;
    12. var SidewaysStiffness : float = 2.0;// 2 just worked better...
    13.  
    I'll explain my theory abit, well car wheels have logical parameters for movement (in longitudinal lateral ways)
    they are slip ratios and slip angles. So i tryed to use slip angle and slip ratio parameters to achieve my friction results.
    The only unrealistic thing i made here, is that I made the curves more like simple peaks, the curves start from 0 and raise a griping position and after that they decrease to 0 or 1.
    In real life this does not happen, in real life both forward and sideways frictions are combined and cut by longitudinal or lateral movement, for this kind of simulation we need a dynamic friction script (withc i was talking earlyer)
    Since i did not manage to create a script that would do such thing, I faked the curves by simply decreasing the curves to 0 or 1 (minimal grip). Its not a realistic solution, but It seems to me that these "mountain" values work quite well actually.

    Obviously some have discovered this before, but i did not find any reference to this, so i decided to share my knowledge. :)

    The car model i found from the internet, and i dont know who the author is, anyway it's only a placeholder to visualise a vehicle ...obviously.


    *NOTE*
    There are alot of other things that need to be fixed (engine torque, gearbox etc.), but i was concentrating on the wheel friction enjoyable handling!

    Image:


    UnityPackage:
    http://www.sendspace.com/file/rlvq8k

    And finally, if you make any changes to it please share your knowledge! :p
     
  2. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    Hey Ravel,

    I'm very very impressed.

    This really does handle very well and interacts with the terrain beautifully.

    Are you able to tweek it a little more so that at high speeds the steering is less sensitive? It seems to turn so sharply at high speeds that you lose speed and the car slides out.

    Also it would be great to get a little move slow speed wheel spin for burnouts and fishtails.

    I've been following every Unity vehicle project for the past couple of years and I think what you have here could be the best handling vehicle I've driven. Sure some may say that others are more realistic in some areas but your project is just what I need - a fun, fast vehicle which drifts, is great at low and high speeds and interacts perfectly with the ground without any strange bouncing or glitching at high speed.

    A BIG Congrats!!!

    If you make any changes please let me know - I'd hate to miss them.

    JeffAU
     
  3. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    pulling the steerangle down from 35 to 20 feels great.

    After driving for a bit longer, I love this car twice as much as I did when writing my comment above.
     
  4. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Are the tail-lights just lights?
     
  5. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Thanks JeffAU, seting the sideways asymptote slip to 30 and value to 10 should make it harder to drift/slide at higher speeds, if i remember correctly haha. For burnouts, i think we need that dynamic friction script, because when a wheel does a burnout, the longitudinalfriction is higher than lateral friction, in pacejka formula this is done by combining the pacejka. Anyway i was aiming at fun but realistic physics, like in gta IV or racedriver grid. About spinouts, in real life, if you steer with such angles in a high speed, the car does one of two things, the car spins out or flips, since this is more like a sports car, it doesnt flip that easly, it simply spins out.

    And yes it's a nice car in real life to haha.

    carking1996, the tail-lights are flares only.
     
  6. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Nice job. Btw, what shaders are you using on the car? It looks awesome!
     
  7. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    I use the standard unity reflective bump/specular shader :)
    I just didnt go nuts over the setup ...as a lot of people seem to set everything to the max, maximum isnt always a good solution haha.
     
  8. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    What reflective map did you use? Can you send it to me? Or, post it here? I love it!! :D
     
  9. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Uhm i added the unity package, i think it extracted all of the media to your hardrive?

    Edit: well i am new to unity, i dont know if i packed it correctly, but JeffAU played it, so i think the media should be stored on your hard drive, in the project that you opened it in.
     
    Last edited: May 5, 2011
  10. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    hmmm ... having trouble getting the AI script working. Hs anyone managed to get it working yet?
     
  11. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    if you want i can make it work after i have changed the engine part(if im going to do that haha)
     
  12. JeffAU

    JeffAU

    Joined:
    Mar 22, 2009
    Posts:
    387
    Yeah Got AI working again. I just grabbed your new Player script and merged in the waypoint code from the old script.
     
  13. Daniel G

    Daniel G

    Joined:
    Mar 5, 2013
    Posts:
    25
    Hello,
    I know you haven't been active for a while but I just wanted to say this project has made my day :D Well my app :p

    It's simple and down to the necessity and thats how i like it :D easy to add on till the cows come home :D

    Thank you thank you thank you!
    Daniel
     
  14. gv

    gv

    Joined:
    Feb 22, 2013
    Posts:
    89
    hey can I ask where you got the car model from ?? I really like it... :)