Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Tank Physics Issues

Discussion in 'Physics' started by Emilyanis, Dec 15, 2016.

  1. Emilyanis

    Emilyanis

    Joined:
    Feb 22, 2014
    Posts:
    17
    Hello to Unity community!

    I am making realistic tank physics in Unity using standard WheelCollider. And now I faced with some problems.

    1. WheelCollider friction on slope.
    Tank can't climb slopes, even on small. For example, 10 degree slope stops tank completely. I played with friction and substeps, but unfortunately its not work. In Unity 4 was been ability to max out friction, in Unity 5 it makes your vehicle explode in space.

    WheelColliders config:

    Substeps is 40.

    2. WheelCollider sleep.
    As you know tank can turn on place, and there is second issue. I dont know why, but when tank turns on an uneven surface and angular velocity falls around ~0.5m/s, WheelColliders dont respond on torque, they like became asleep, tank just stops, and start again, and so on. However on flat surfaces its doesnt happen.


    I tried a lot of things, and none of them didnt work, maybe you know how to fix this, Thanks!
     

    Attached Files:

    • wc.png
      wc.png
      File size:
      21.6 KB
      Views:
      235
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    Easiest fix is dont use wheelcolliders for a tank. They dont make any sense for tanks.
     
  3. Emilyanis

    Emilyanis

    Joined:
    Feb 22, 2014
    Posts:
    17
    In Unity 4 it works pretty well. So there is no workaround in Unity 5? What I need to use for tanks instead?
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,224
    @Emilyanis Your issues are related to the WheelCollider itself in Unity 5. You'll encounter the same issues when simulating any vehicle in Unity 5. These problems are caused by the bad design and implementation of vehicles in PhysX, the underlying physics engine used by Unity. The best solution so far is using any of the vehicle packages available at the Asset Store as starting point, instead of the WheelCollider alone.

    @JamesLeeNZ I think that WheelColliders can also be used for track-based vehicles. They can do a good job as long as the wheels on each side are configured to rotate together (hard link). Of course there are some limitations, but still is an easy and convenient method.

    upload_2016-12-16_12-10-20.png
     
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    I consider wheelcolliders on a tank a bunch of un-nessesary physics work, for little gain, especially considering that real tanks dont work this way... Its the tracks that cause the movement (yes I know the wheels drive the tracks).

    Personally I use MovePosition/MoveRotation and think it works the best for tanks.

    Its not like the wheelcolliders are some amazing tech that should be put into everything that has a wheel... They are notorious for being the opposite of amazing tech..
     
    Dennis_eA likes this.
  6. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,224
    I thing the wheel approach is very convenient for simulating the torque and friction accurately in tracks. I don't mean WheelColliders specifically, but using "wheel entities" as tracks.

    Each track receives a specific amount of torque. This is all the torque the entire track can convert as traction force. Each single segment in the track is supporting a specific load value. Thus, it can apply traction and provide friction in a specific way different from the other segments.

    Example: if only one segment of the track is making contact with the ground then all the torque provided to the entire track will be applied as force by that single segment. If many segments are touching the ground then the provided torque will be delivered among these segments and they will convert it into forces based on their specific situation.

    Thus, tracks can be "easily" modeled as wheels: it just requires a constraint among all the wheels for them to co-rotate at the same exact rate. With this constraint properly implemented any torque applied to the track will be delivered to the wheels so the wheel set accurately behaves as a real track, including forward and sideways sliding based on the coefficient of friction of the track with the ground, torque applied, and velocity of movement of the track (= rotation rate of the unified wheel set).

    As sidenote, this is also the model used by PhysX for Tanks:
    http://docs.nvidia.com/gameworks/co...guide/Manual/Vehicles.html#pxvehicledrivetank
    "Tanks are different to multi-wheeled vehicles in that the wheels are all driven through the differential in a way that ensures that all the wheels on the left-hand side have the same speed, and all the wheels on the right-hand have the same speed"

    My own implementation doesn't even need a differential. It uses two independent Direct Drive engines, one per track, simulating the real hydraulic engines that move the tracks in most track-based vehicles.
     
    Maeslezo and TooManySugar like this.
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    Still not convinced.

    The biggest benefit of the wheel collider is steering. If I dont need car steering behavior, I dont use a wheel collider.
     
  8. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,224
    I can speak for my own experience only. Having two rows of wheels (WheelCollider) with no steering can conveniently simulate tracks and provide steering behavior. Just make each row rotate at different rates and the vehicle will steer as result. One side row rotating forward while the other rotates reverse at the same rate provides the so called "neutral rotation", where the vehicle spins around its center.

    This technique actually works pretty good simulating some uncommon vehicles:

    upload_2018-8-24_0-4-59.png
    upload_2018-8-24_0-5-27.png

    In the latest case, none of the 8 wheels has steering but each row of wheels can rotate at a different rate. This provides all possibilities of steering, from very slight steering to neutral rotation.
     
    Maeslezo likes this.
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    1,942
    If you don't need super accurate physics (like wheels on tank tracks), (in most cases don't) you can easily apply torque, or opposite forces for turning, to rigid body, to get same result. Much cheaper for performance reasons. And most cases, unnoticeable.

    There was post recently, where OP wanted to apply wheels physics to a train. For game application, such are unnecessary.
     
  10. jpmartin

    jpmartin

    Joined:
    Mar 6, 2015
    Posts:
    1
    @Edy how do you control sideways friction of the wheel colliders for steering? Are you doing it dynamically by speed? I.e low speeds have more slip to allow for zero turn radius?

    Also, any tips on setting mass for tanks? Im struggling to figure out the relationship of tank mass, wheel mass, spring and damper values, and wheel torque.

    Thanks!
     
  11. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    1,942
    Few years back I was modding wheel system for one of games.
    If I recall correctly, I used side forces per wheel to turn, as I described above.
    And traction made by sideways friction.



    But with new wheel system, don't know if that same setting will work. Probably not.
     
  12. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,224
    I assume you're referring to this vehicle, as it's a wheeled vehicle that allows neutral steering (zero radius):

    upload_2018-9-18_1-25-18.png

    All 8 wheels are standard wheels with no special considerations. The 4 wheels in each row are "linked" so they're forced to co-rotate at the same exact rate. Just imposing different rotation rates at each side causes the vehicle to steer. Rotating one side forwards and the other side reverse at the same rate causes a neutral steering (the vehicle rotates around its vertical axis). It's the same as in the real vehicle.

    I'm using real-scale masses. I.e. the bulldozer weights around 110 tons. For suspension, you may follow the guidelines here as starting point:

    https://vehiclephysics.com/user-guide/vehicle-setup/#suspension