Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Can't get wheeled robot physics to behave

Discussion in 'Physics' started by Woz4tetra, Jan 4, 2024.

  1. Woz4tetra

    Woz4tetra

    Joined:
    Oct 24, 2022
    Posts:
    2
    Hey folks, I've been using Unity for robotics simulation and am having trouble getting vehicle physics to behave. I've tried numerous solutions but none really get an optimal solution.

    This gif illustrates my current problem:

    In this little demo, the only inputs I'm giving are forward and backwards on my keyboard. And yet, when I press forward on the keyboard, the robot rotates left or right (seemingly in alternating order). Driving backwards is fine. I've confirmed with print statements that I'm not commanding it to rotate when pressing forward.

    Things I've tried to fix this
    • Adjust wheel, castor, and floor physics - Changing coefficients of friction seems to have no effect
    • Increasing robot mass - This straights it out but I have to set it unreasonably high (robot is ~1 kg, setting it to 4 kg works). The problem is it never reaches the desired speed and the wheels seem to be spinning excessively at moments
    • A PID controller - The PID does its job, but the wheels are visibly slipping and so not having an effect in correcting the trajectory
    • Moving colliders in front of the robot. This seems to push the center of mass over the wheel axle more which solves some the dynamics problems. With this it turns much more sluggishly. This is also not accurate to the real robot since its center of mass is not over the wheel axle. The robot is much tippier which causes parts of the collision to drag on the ground.
    • Wheel colliders - I've never gotten these to work properly. Wheels free spin or the whole robot spins over itself instead of moving.
    Are there guides in Unity for accurate vehicle simulation. There's a bunch on cars, but those don't really capture the dynamics I'm looking for.

    Link to relevant code:
    https://github.com/Woz4tetra/true_b.../TrueBattleBotSim/Assets/Scripts/RobotControl
     
  2. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    105
    Hi,
    I've used Edy Vehicle Physics to make this robot fighting game "prototype" with my son:
    https://biscuitsmitten.github.io/Carnage/
    (Hmm, the WebGL build isn't great, kindof juddery and a bit laggy, I made it just now to share - WASD + space, maybe controllers will work (maybe *two* controllers will work!))
    I'm using Robot Wars style masses of around 100kg.
    It's probably not very simulatey, but it feels OK to play. I'm not sure how simulatey you want to be.
    I feel like vehicle simulation is hard, using something like EVP solved a lot of problems I didn't even know would be problems. Edy also makes a more complicated & "realistic" VPP product (free but various limitations).
    Your demo looks very cool! It makes me want to revisit the game my son was making (we kindof stalled on spinner weapons, applying torque to the spinner was making the robot hard to steer (I think due to "counter-torque")).
    Edy Vehicle Physics (& VPP) will only work with enclosed, "downward-pointing" wheels, due to it using the Unity/PhysX WheelCollider. You can roll your own wheel code to put under EVP (is what I've ended up doing in my other stuff), or perhaps try some of the 3D/ Volumetric wheel colliders on the asset store if you need exposed "3D" wheels (I didn't have much luck with them, but this was years ago).
     
  3. Woz4tetra

    Woz4tetra

    Joined:
    Oct 24, 2022
    Posts:
    2
    Thanks! I'll check those packages out. It seems I need to do some research on how physics simulators work. It feels like I'm guessing randomly. If this package solves everything, then great! If it only works out of the box for 4 wheeled sedans then I may be in the same place I am now. I'll give it a shot though.

    I got around the spinner problem by having a collider that applies an explosive force on contact. Doesn't realistically depict gyroscopic procession but that's a problem for another day.

    I realized my posted GIF never got uploaded. I'm attempting to upload again.
     

    Attached Files:

  4. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    105
    I think Edy vehicle physics works for up to 20 wheels per vehicle in any arrangement.
    It has full source, I think you'll need light mods to the input-reading controls to get tank-steering.
    Main limitation is, due to using Unity/PhysX WheelCollider it's fine for enclosed wheels like on the robot wars robot 'eruption', but won't work properly for exposed wheels like 'carbide' (both the upper and lower wheel surfaces are exposed on carbide, unity wheel collider will do one or the other (maybe you can live-switch), but not both at once). Robots like 'Stinger' with fully exposed wheels will be kindof garbage with Unity/PhysX Wheel collider, but if you sub in your own mesh-based collider (which is a bit of work), VPP will drive it ok.
    is a good example of what stock WheelCollider can't do.
    If you need exposed wheels, your own mesh-based wheel collider should be able to achieve what the tatsu collider is doing, I think I'm doing something similar. It should work well as-is for properly flat arena-like terrain, needs some finessing for bumpy terrain.
    I'm using ArticulationBody springs for suspension, but that was originally for a full size vehicle. I reckon you could probably get away with fixed wheelmeshes and give VPP constant wheelhit force for robots, as least as a first go at getting stuff working.
     
  5. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    105
    Oops, can't edit my post on my phone.
    Explosive hits from spinners sound like a great way to make them work!