Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dynamic tank tracks - Proof of concept

Discussion in 'Scripting' started by ForceX, Feb 8, 2011.

  1. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    So i've been working of a way of having the portion of a tanks tracks that touch the ground be able to follow the contours of what it's touching. My thoughts on how to do this are..

    1. Have a mesh object that has many edge loops.
    2. Create an array of bones spaced evenly along the mesh.
    3. Weight the bones to the mesh.
    4. Make the Bones a Rigidbody and give them sphere colliders.

    4a. (Alternate method untested idea) Use Raycast to get distance to the ground.

    Here are the results for the Rigidbody method.

    Thoughts, ideas, suggestions are more than welcome, as i am only just now starting to explore this problem i am curious as to what you think, or any different way of solving this.
     
  2. Hypnagogia

    Hypnagogia

    Joined:
    Jan 15, 2011
    Posts:
    3
    Looks like a solid idea, but my initial question is how do you plan to handle the full loop of the track?
    I figure you'd need something inside the loop to keep it open, but would the top of the loop not be causing pointless collision checks while not touching the ground?
     
  3. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    The track rotation will be handled with texture offsets. The geometry will not rotate. This is just to get the illusion that the track is conforming to the ground.
     
    Last edited: Feb 8, 2011
  4. justicar

    justicar

    Joined:
    Dec 21, 2010
    Posts:
    78
  5. Larsa334

    Larsa334

    Joined:
    Jan 7, 2011
    Posts:
    39
    I'm making a tanksimulator and used your alernative 4a with very good results.

    Here is an old example,it has some now fixed bugs.But because the game now is a network multiplayer I didn't have the time to convert it back to a singleplayer again just to show an example. :)
    The biggest problem was how to make the treads not deform too much when the wheels had no contact with the ground ( the example doesn't have that fix so the treads extend forever if you drive out of bounds).

    http://dl.dropbox.com/u/20727661/TestTiger/WebPlayer/WebPlayer.html

    Drive with the arrowkeys
    U,I,O for different cams
    A and D to turn the turret
    W and S to move the gun
    SPACE for shooting.
     
  6. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    Hey that's pretty cool. Indeed the tank tread movement looks very realistic. I hate to nitpick but I have a small suggestion, in the version you posted it seems like you can't turn the tank while it's not moving forward. Real tanks do this quite well by moving one tread in reverse while the other moves forward, it certainly helps getting around tight areas.
     
  7. Larsa334

    Larsa334

    Joined:
    Jan 7, 2011
    Posts:
    39

    Yes,real tanks post-1945 all have the ability to turn on the spot.

    I know that German tank-ace Michael Wittman used this technique to quickly change target.

    The Tigertank couldn't even fire when driving without damage to the turretring because of the turrets weight and the forces of recoil.
    The gearbox frequently broke down even when driving on roads because it was underdimensioned for the 56.9 tonnes the Tiger weighed in at.
    That's German engineering for you *joking*.

    EDIT: Older tanks pre-1945 could put brake on just one tread (the German towerless StuG used this technique to aim its gun) and turn that way,but they couldn't drive one tread in a opposing direction like modern tanks can.
    I want to reduce the Tigers aimingspeed so the Firefly can have a chance,otherwise no one will ever play on the "Good guys" side. :)
     
    Last edited: Feb 11, 2011
  8. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Larsa334, Nice demo i like what you've got. What was your method for the track rotation, Just have the texture drive the animation to make it look as the track is moving?

    In the post above you mentioned that the track will extend for ever if the conditions are right. So i'm sure you probably fixed this but if not you could limit the amount the track drops by limiting how far from the Raycast origin it is allowed to move. You can also limit how far the Ray can cast out too.
     
  9. Larsa334

    Larsa334

    Joined:
    Jan 7, 2011
    Posts:
    39
    It is all done with textureoffsets.I used a diffuse detail material on each track so the same value is fed to both base and detail-offset.

    Yes,I have fixed that bug. :)



    The raycast in the middle of the wheel moves both the treadbone and the wheel so that the whole package stays on their separate offsetvalues from the ground.

    Then the upper "stopper"-raycast have a limiting value that determines when both the wheel and tread have reached its lowest allowed Y-value.
    The two drivewheels on each side is naturally connected to the tanks body and don'thave raycasts at all.

    I have made a new thread in showcase:

    http://forum.unity3d.com/threads/77329-Tankshooter

    I have also uploaded a much newer build of the demo there too.
     
  10. Larsa334

    Larsa334

    Joined:
    Jan 7, 2011
    Posts:
    39
    I thought a lot about what Antitheory said about rotating on the spot!

    The solution I came up with to make it "historically correct" was to make one separate pivotpoint per track.

    I then used transform.RotateAround to rotate the tank around them.

    Please try it out in the webplayer and say what you think. :)

    There is a little problem when the two rotationmodes (stopped and moving) switches,but I think I can tweak the variables to make it disappear.
    Maybe use lerp....

    http://dl.dropbox.com/u/20727661/NetTiger/WebPlayer/WebPlayer.html

    I haven't had the time to fix the UVoffsets when rotating yet.


    Here is a picture of where I placed the two pivotpoints:
     
    Last edited: Feb 15, 2011
  11. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    If you were going that route, you would add a single raycast and use the normal of the hit to develop the rotation of the tred.
     
  12. Larsa334

    Larsa334

    Joined:
    Jan 7, 2011
    Posts:
    39
    Interesting!I send the tanks velocity as serialized info over the network to turn the wheels and offset the treads.I tried to use rigibodyvelocity to reconstruct the speed but it worked very poorly.

    I have to look into how this works.
     
  13. callahan.44

    callahan.44

    Joined:
    Jan 9, 2010
    Posts:
    694
    I implemented some nice tracks for one of my tank projects. It was in Lightwave but the principles could be applied to Unity.

    Closed loop of "cloth" made up of polygon lines, with the friction of the front/rear drive wheels moving it. The hard links were orientated along the length. With gravity and collision with the ground/rollers, it looked pretty realistic.

    Shame I lost all that stuff in a HD meltdown. :(
    This was the tank. http://steamrolled-media.net46.net/portfolio/CGI/Misc/Tank_mkIV_Still.jpg
     
  14. Larsa334

    Larsa334

    Joined:
    Jan 7, 2011
    Posts:
    39







    Your tank is a male tank and mine is female.Maybe we'll let them meet sometime?Who knows what would be the result of such a meeting?!? ;)
     
  15. Vaghinak

    Vaghinak

    Joined:
    Dec 31, 2012
    Posts:
    1
  16. vagho

    vagho

    Joined:
    Mar 25, 2013
    Posts:
    85
    Tank Track Simulator

    http://u3d.as/content/vaghinak/tank-track-simulator/4MA



    - Based on the component Physics / Hinge Joint
    - Well controlled on uneven terrain
    - The tracks are created from individual pieces, that look very realistic
    - Track simulation not fully based on physics, because of this, does not require a lot of computational memory.
    - Turret also can controlled
     
    Last edited: Nov 28, 2013
  17. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Another option for tank tracks that is very fast and works very well over terrain with a little extra scripting, ie simple raycast from the knot positions.