Search Unity

Question How to make stable vehicle suspension with ArticulationBody?

Discussion in 'Physics' started by Robert-O, Nov 9, 2023.

  1. Robert-O


    Sep 12, 2023
    As part of a bigger project I am looking to create suspension for the wheels of a small vehicle.

    The vehicle is made of objects with Articulation Body components: a main body and 4 wheels, each just a cylinder with a revolute joint to the body. This works fine, the whole thing will roll around happily when I tip the terrain for example.

    But now I want to add suspension also. So for each wheel I add an object with Articulation Body and give it a prismatic joint with some stiffness/damping. This seems to work okay, when the car drops the suspension gives way a bit and bounces around.
    However, the car won't roll around normally anymore. When at standstill, the wheels and body seem to bounce around a bit without end. And when tipping the terrain it looks like the vehicle has a lot of resistance.

    Is there something wrong with my approach? I can't see how this shouldn't work.

    Screenshot and demonstration project are attached. Using URP and Unity 2022.3.5f1.


    Attached Files:

  2. codebiscuits


    Jun 16, 2020
    One problem is is your "Wheel" prefabs are colliding with your "Car Body". I think this is causing the jitter you described.
    The capsule collider isn't scaled by the wheel transform scale.
    One way to fix this is by assigning the Wheel prefab child object's CapsuleCollider to, e.g., a "Wheel" layer, and assigning the "Car Body" to a "Body" layer, and turning off collisions between those layers
    Ah, I think you can do this per-object actually with LayerOverrides in Unity 2022 (I mostly use 2021 rn). You can also do it in code, and I thought there was a "don't collide with parents" thing, but maybe that's only RigidBody.

    I don't think you need a "Suspension_Base" ArticulationBody or GameObject.
    Your Car Body weighs 100kg, your wheels weigh 5kg and your suspension spring weighs 1kg. I'd maybe go with ~real world values (no idea what to do for suspension spring, I'm not sure how sensitive the physics maths are to small values), I'm not sure how sensitive articulations are to a 1:100 mass ratio between joints.
    You have a 90 degree Anchor Rotation in your prismatic joint, which I don't think you'll need, but I found all the anchor stuff pretty confusing:)

    I wasn't brave enough to try actually spinning actual meshes to make friction to drive my vehicles. My feeling is that because the wheels and terrain won't have any squish in them, you'll lose contact quite a bit, perhaps even on smooth surfaces, for sure on bumpy terrain. I had the same problem tbh.

    I found I had to crank up the fixedTime step (120Hz), Solver Iterations, Solver Velocity Iterations to get my suspension to behave nicely, but this was some time ago, & I've not revisited it, maybe I can ease off a bit.

    Depending on your requirements, I'd really recommend Edy Vehicle Physics or Vehicle Physics Pro. Neither will really work as-is for large protruding wheels like your example project (like, e.g., a monster truck), but for normal cars on normal roads they're great if you're careful with your colliders, I think.
    Last edited: Nov 9, 2023
  3. Robert-O


    Sep 12, 2023
    Thanks @codebiscuits , I'll look into the collision stuff and physics settings!

    Myeah, a plugin like that would be practical. I also now found the wheel collider object. However, I am generating my world from a URDF description, so I am kind of limited to the Articulation Bodies.

    EDIT: Yup, the collision box was the problem! With the box collider reduced my little car works as I'd expect.
    Unfortunately, my real project still shows the same problem. When I can reproduce this with a demo I might come back.
    Thanks again.
    Last edited: Nov 10, 2023