Search Unity

How to simulate cargo loading using Wheel Colliders?

Discussion in 'Physics' started by Marcos-Schultz, Apr 17, 2020.

  1. Marcos-Schultz

    Marcos-Schultz

    Joined:
    Feb 24, 2014
    Posts:
    381
    Hi, I'm trying to do something simple, load something heavy on a truck, which is simulated using WheelCollider.

    The truck has a mass of 5000, and the cargo has a mass of 3000.
    The problem is that every time the truck climbs on a step (for example, the curb), the WheelCollider is teleported upwards, and this throws the truck upwards, which in turn makes the load jump.

    The problem is best illustrated in the image below.



    Both Rigidbodys have the same type of simulation, (Interpolate = Interpolate, CollisionDetection = ContinuousDynamic).

    What should I do to solve this problem where the load simply bounces?
     
  2. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    Random thoughts:
    Unless you have to, I would not leave the retention of the cargo to collision detection: Have a process to connect (fixed joint) the cargo to the truck for transport and then release when necessary.

    Try to avoid scenery objects that present discontinuities to the wheel colliders, e.g. have angled faces on the curbs.

    In all but the worst discontinuity problems, the wheel collider should not be "teleporting" are you sure the suspension characteristics are OK?

    Check your cargo physics material bounciness is 0; You could increase the number of physics solver iterations, but that is a potentially a big overhead.
     
    Marcos-Schultz and Edy like this.
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    You may also try reducing spring and damper to reduce the impulse caused by the WheelCollider when hitting the bump. Angled faces on the curbs (not necessarily in the visual mesh, but in the collider only) is the workaround that is closest to an actual solution.

    You could ultimately blame Unity for those problems. The wheel entity in PhysX has already methods for preventing that to happen, but they haven't been exposed / opened in the Unity side:
    • The arbitrary decision to make WheelCollider.sprungMass read-only prevents us to tell the WheelColliders that they're actually carrying some cargo other than the vehicle's mass. Therefore working around the spring and damper as mentioned above is a trial & error procedure, without any guarantee of setting actually correct values.
    • The Wheel Sweeps feature has been available in PhysX for nearly three years now (PhysX 3.4), but it hasn't been exposed yet. This would prevent the wheel to be "teleported" when encountering steps. Instead, the steps would be smoothly climbed without applying sudden impulses, as happens now.
    I've been requesting these features to be exposed since more than two years now (writable sprungMass since 2015) yet today they haven't entered any development cycle. Probably they're "forever in the backlog". It's understandable that other engines (that also use PhysX) are better considered as suitable to create vehicle simulators than Unity, despite our efforts.
     
    Last edited: Apr 18, 2020
    Marcos-Schultz likes this.
  4. Marcos-Schultz

    Marcos-Schultz

    Joined:
    Feb 24, 2014
    Posts:
    381
    Thank you very much for your answer Edy ... I was able to understand some information that was just present in my mind.

    I have been planning to create my own WheelCollider for over 2 years, but the fact that it is not possible to implement 'substeps' has caused certain problems for me to achieve something stable.

    I noticed that your product (Edy Vehicle Physics) from the Asset Store seems to respond to this type of situation much better than my product. Any special secrets?

    Again, thank you for always answering the most complex questions about physics ... I REALLY wish you were the official developer of this part at Unity, but for now, I think we have to live with what we have.
     
    Edy likes this.
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    Thank you :)
    Possibly the experience of dealing with the WheelCollider almost every day for the past 10 years counts ;)

    Maybe an issue that is easily bypassed is the case of the suspension being compressed beyond the configured suspension distance. When that happens bad things will happen in the PhysX side. This is easy to happen when hitting a curb, especially when the suspension is unexpectedly compressed due to added load. That might be the case in your setup: always ensure the suspension to have room enough for both the truck and the load so hitting a curb won't make the suspension to reach its travel limit. As sprungMass is read-only, we don't have any proper way to make the WheelCollider to be aware of the added load.
     
    Marcos-Schultz likes this.
  6. Marcos-Schultz

    Marcos-Schultz

    Joined:
    Feb 24, 2014
    Posts:
    381
    Wow, that's exactly it.

    I can make the suspension extremely rigid, but if it is long enough that it does not compress to the maximum when teleporting, the problem goes away.

    It's amazing ... You really understand the mechanisms involving PhysX and Unity. Thank you!
     
    Edy likes this.
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    My pleasure!
     
  8. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    WheelCollider is one area that received very little attention over the years, I have to admit.

    The only thing we rolled out recently was the WheelColldier.suspensionExpansionLimited flag. I do hope to expose what Edy asks with the next occasion, but, unfortunately, no estimates right now.
     
    KouroshX98 and Edy like this.
  9. Marcos-Schultz

    Marcos-Schultz

    Joined:
    Feb 24, 2014
    Posts:
    381
    @yant

    Any news regarding the WheelColliders? Will we ever have some kind of smoothing when the wheels collide with the obstacles of the scene?
     
  10. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    Marcos-Schultz likes this.
  11. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    374
    ¿Y qué opción consideras más potente en este sentido? ¿Unreal?
    Gracias.
     
  12. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    Unreal also uses PhysX. While WheelCollider.sprungMass has been recently exposed for read/write in Unity, I wouldn't expect wheel sweeps to be available anytime soon (with "soon" meaning within next ~3 years). At least in Unreal you could use the PhysX API directly, so all features would be available.
     
    Barritico likes this.