Search Unity

[WIP][Released] WheelController - Realistic Three Dimensional Alternative to WheelCollider

Discussion in 'Works In Progress - Archive' started by NWHCoding, Aug 11, 2016.

Thread Status:
Not open for further replies.
  1. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Do you have plan to make your vehicle physics with WC3D ?
     
  2. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    I will be picking up this asset and attempting to integrate it with my custom physics solution that is meant to more or less be a realistic simulation. The Unity wheel collider has many problems with damper, suspension, and various raycast problems that I hope aren't present in this collider. I will post my findings once I am done with this. :)
     
  3. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    A new update will be on the way soon (v1.9). I hope to ship it today but it will take a few days to appear in the store.
    One of the customers has brought to my attention that when spring strength is set to a low value and the car e.g. jumps suspension will bottom out which is not properly handled. If you need a quick fix for this you can set your spring force to some high value (that will be the bottom out force that mimics suspension hitting the stopper) - in this case 80,000 - and then making your spring curve look like in the screenshot below. Curve up to the first point is the real suspension curve and the part between the first and second (last) point is the part that handles bottoming out since the spring compression is on the horizontal axis and force coefficient on the vertical.
    This is a bit of a workaround for those of you that might need this and don't want to wait for the update.

    upload_2017-7-10_9-19-1.png

    EDIT: Update is finished but will take a few days to appear on the store. If you need it sooner send me an email with your invoice number and I will mail it to you.
     
    Last edited: Jul 10, 2017
  4. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    V2.0 has been submitted for review and will be out in a few days.

    Version changes:
    - Reworked suspension to fix a few bugs that were reported (jittery wheels, jumping sideways, wheels partially falling through ground).
    - Reworked rim collider which is now box shaped.
    - Added tank to the demo scene (no tracks, only wheels).
     
    strich likes this.
  5. DiscoFever

    DiscoFever

    Joined:
    Nov 16, 2014
    Posts:
    286
    Interested in getting your asset; does it include skidmarks generation ? or can you eventually help me implement it ? thanks
     
  6. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,486
    Would be amazing if you could simulate softbody style physics! Maybe detect impact on raycast and lessen that area for a short moment, just a thought.
     
  7. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Yes, please!

    Is the physic sliding different for each angle? I mean, If I'm braking, it slows down faster (along Z axis) than if I'm sliding (sideslipping along the lateral X axis)? and if it is, are this inspector input values a curve per angle? and if is not can you include it?
     
  8. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    No, it does not. I find that to be more in the area of the vehicle physics assets - such as the one I am developing at the moment. On the bright side this looks promising - you will need to change it a little bit to work with my asset but API is similar enough that it should not be more than a few minutes of work: https://github.com/Nition/UnitySkidmarks

    Soft-body physics are very expensive. I am not sure what "lessen" would mean in this context, maybe deform the tire?
    I have been testing that out since the beginning of the asset, but anything more than fake deformation (like mesh deformation) becomes quite expensive. I will look into it some more since it seems everyone wants it :)

    I guess you wanted to ask if lateral and longitudinal friction are different. Answer is yes. You could set the car to grip well when accelerating but skid as if on ice in the corner. There are curves and options for both lateral and longitudinal friction as seen here:

    2017-09-20_21-21-15.jpg

    Effect of any of those two frictions is calculated from dot product of wheel's forward vector and direction of travel of the wheel, so the sliding angle definitely affects handling.
     
    AlanMattano likes this.
  9. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Thx NWH! Just one more idea: I wish that @SpookyCat makes a new specific asset for tire deformation that you can integrate compatibility with. Or look if inside their deformation tools there is a way to use it with this asset.
     
  10. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    The 'problem' is not that huge and it is quite easy to implement tire deformation BUT a decent quality mesh is needed along with moving a few hundred vertices per frame. It is viable and works on PC (I still have the project somewehere) , and since interest seems high (you are not the first to ask) I will do the deformation, post a video or two and then include it in the asset if the reception is good.
     
    AlanMattano likes this.
  11. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,486
    Cool! :) hopefully it won't be too expensive performance wise, I'm only think of wheel collider deformation, for the fake look..
     
  12. J-F

    J-F

    Joined:
    Nov 8, 2012
    Posts:
    101
    Can the suspension return current compression values? I'd like to use them to make an animated suspension model.
    Getting the suspension compression value from the default wheel collider isn't currently possible.

    Also, as for the softbody physics.
    I've faked wheel deformation before with shaders.
    And in animations i've used lattices to deform a certain side of a mesh independant of its orientation.
    Maybe a simillar deformation could be achieved with these wheel-colliders using vertex displacement shaders too?
     
    Last edited: Sep 27, 2017
  13. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Yes it can. Just use wheelController.spring.compressionPercent. Fully compressed is 1, fully extended is 0. You can also get current spring length.
     
    AlanMattano likes this.
  14. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Version v2.2 has been uploaded to the Asset Store and will be available in a few days.

    Changes:
    - New demo scene.
    - Removed camera distance lag and camera does not go through terrain anymore.
    - Fixed all "value is never used" warnings.
    - Fixed compressionPercent in edge cases (bug since 2.0).
    - Updated documentation.

    Wheel deformation has been pushed to 2.3 since I wanted to get the fixes out as soon as possible, and deformation will take some time.

    2017-10-01_14-09-31.jpg
     
    Last edited: Oct 1, 2017
    strich likes this.
  15. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    How about your own vehicle physics that using this asset ? Are you have plan to make vehicle physics ?
     
  16. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Yes and they are in the making. I was working on the masters thesis parallel with that and that is the reason it was taking some time, but now that I am in the clear it will go much faster.
     
    strich likes this.
  17. J-F

    J-F

    Joined:
    Nov 8, 2012
    Posts:
    101
    How well does this handle vehicles with more than 4 wheels?
     
  18. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    WC3D is alternative to wheel collider - not the vehicle physics (simple vehicle script excluded). You can have as many of them as you want, much like with the wheel collider.
     
  19. J-F

    J-F

    Joined:
    Nov 8, 2012
    Posts:
    101
    What im asking about is that do i need to increase the physics update tickrate or something like that?
    Usually having more than 4-6 wheels on a car with unity's default wheel collider makes it unstable unless you increase the vehicle supsteps to accomodate for the increased wheel count.
     
  20. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I have made a tank once using WC3D with 24 or so wheels, it worked fine without any changes to settings. Same for 6x6.
     
  21. imdadahmadmian

    imdadahmadmian

    Joined:
    Oct 13, 2017
    Posts:
    3
    hi @NWHCoding nice work but i am facing some problems with wheels controls .when i add the carcontroller script to the car and add all colliders ,the car move forward and backword accuratly but not turning left and right.please suggest possiable soultion.thnx
     
  22. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I am guessing you need to tick the checkboxes named "steer" on the wheels you want to steer. This can be done by expanding the wheel options in the VehicleController script.
     
  23. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96
    Hi, I'd like to adapt the popular antirollbar script to your great asset, but for some reason it always returns 0 for the springCompression. Could you please give me a hint, what am I doing wrong?

    Original antirollbar script for WheelCollider:

    Code (CSharp):
    1.     public void FixedUpdate()
    2.     {
    3.         WheelHit hit;
    4.         float travelL = 1.0f;
    5.         float travelR = 1.0f;
    6.  
    7.         bool groundedL = WheelL.GetGroundHit(out hit);
    8.         if (groundedL)
    9.             travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;
    10.  
    11.         bool groundedR = WheelR.GetGroundHit(out hit);
    12.         if (groundedR)
    13.             travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;
    14.  
    15.         float antiRollForce = (travelL - travelR) * AntiRoll;
    16.  
    17.         if (groundedL)
    18.             m_Rigid.AddForceAtPosition(WheelL.transform.up * -antiRollForce, WheelL.transform.position);
    19.  
    20.         if (groundedR)
    21.             m_Rigid.AddForceAtPosition(WheelR.transform.up * antiRollForce, WheelR.transform.position);
    22.     }
    My adaptation attempt:
    Code (CSharp):
    1.     public void FixedUpdate()
    2.     {
    3.         WheelController.WheelHit hit;
    4.         float travelL = 1.0f;
    5.         float travelR = 1.0f;
    6.  
    7.         bool groundedL = WheelL.GetGroundHit(out hit);
    8.         if (groundedL)
    9.             travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.springCompression;
    10.  
    11.         bool groundedR = WheelR.GetGroundHit(out hit);
    12.         if (groundedR)
    13.             travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.springCompression;
    14.  
    15.         float antiRollForce = (travelL - travelR) * AntiRoll;
    16.  
    17.         if (groundedL)
    18.             m_Rigid.AddForceAtPosition(WheelL.transform.up * -antiRollForce, WheelL.transform.position);
    19.  
    20.         if (groundedR)
    21.             m_Rigid.AddForceAtPosition(WheelR.transform.up * antiRollForce, WheelR.transform.position);
    22.     }
    23.  
    Anyway, is the springCompression is the same as the suspensionDistance with the WheelCollider?
     
  24. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    No need for all that nastiness. Since WheelController3D exposes much more than the default wheel collider, you can simply do this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AntiRollBar : MonoBehaviour {
    6.  
    7.     public WheelController leftWheel;
    8.     public WheelController rightWheel;
    9.  
    10.     public Rigidbody rb;
    11.  
    12.     public float antiRoll;
    13.  
    14.     void FixedUpdate () {
    15.         float travelL = 1.0f;
    16.         float travelR = 1.0f;
    17.  
    18.         float leftTravel = leftWheel.springCompression * leftWheel.springLength;
    19.         float rightTravel = rightWheel.springCompression * rightWheel.springLength;
    20.  
    21.         float antiRollForce = (leftTravel - rightTravel) * antiRoll;
    22.  
    23.         if (leftWheel.isGrounded)
    24.             rb.AddForceAtPosition(leftWheel.transform.up * -antiRollForce, leftWheel.transform.position);
    25.  
    26.         if (rightWheel.isGrounded)
    27.             rb.AddForceAtPosition(rightWheel.transform.up * antiRollForce, rightWheel.transform.position);
    28.  
    29.         Debug.Log(antiRollForce);
    30.     }
    31. }
    Tested it just now on a clean project and it works as expected. You were getting problems because WheelController.WheelHit returns point as world coordinate, while Unity's does it as a local coord.
    This above is just a simple script, it could be done more elegantly I guess but for the sake of example here it is (anti-roll bar is more of an exponential function in reality).

    Regards
     
  25. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96
    Thank you, just works!
     
    NWHCoding likes this.
  26. Fortitude3D

    Fortitude3D

    Joined:
    Sep 7, 2017
    Posts:
    155
    Cute package man, thanks for the share :)
     
  27. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    An update is coming at the end of the week with some significant changes to the handling and overall feel of the vehicles.
    Some improvements have been made to the API as well.

    Also, layers are now selected through layer mask. Only the ticked layers will be detected.

    LayerMask.png
     
    Last edited: Feb 27, 2018
    AlanMattano and Freznosis like this.
  28. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    From now on all the discussion regarding the Wheel Controller 3D will be moved to the other thread. Existence of two threads (one in WIP and one in Assets forums) is confusing and unnecessary. As soon as I find a moderator I will request a lock.




    Click here for the correct thread.



     
Thread Status:
Not open for further replies.