Tank tracks in BGE?

I need to make a rig of tank tracks that automatically move when the tank is moving, automatically turn when tank is turning, stay at the same level as the tank, etc etc etc. Is there any way without a huge python script?

It’s pretty easy to fake it with a simple UV scroll script:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

scene = bge.logic.getCurrentScene()

if "ini" not in own:    
    own['track_list'] = [ob for ob in scene.objects if ob.get("tracks")]
    own['ini'] = True

for ob in own['track_list']:  
    mesh = ob.meshes[0] 
    mat_id = 0
    length = mesh.getVertexArrayLength(mat_id)  

    speed = 0.005
    for v in range(0,length):
        vert  = mesh.getVertex( mat_id, v)

        uvc = vert.getUV()
        uvc[0] +=speed

I wouldn’t suggest going any further down the road of building real tracks and animating them.

  1. No one is going to notice the hard work you did.

  2. With the time taken on such a minor detail, you’re unlikely to get anything else done.

  3. Such a system is unlikely to be useful elsewhere in any game I can think of, so even though you’ll probably learn something doing it, the result is unlikely to be in the form of transferable knowledge.

A game that has animated tank treads in it.A character could place a gun on the tanktreads and then let it bring it to the person on the tank.If the tank is going slow enough.You might be able to use tank treads to sling rocks at the enemy.

Okay. Thanks for the UV scroll code! Could I not get the speed for the track and play the track moving animation at the speed that the tank is at? That couldn’t take long could it?

If you do want to animate the track all you have to do is animate the first quarter rotation of the track and loop that, heres an interesting read on the subject: http://simonschreibt.de/gat/lego-batman-crawler/ ; That describes how they did it in the lego batman games!

Sure. The UV code has a variable (speed) which you can set by making it a property.
The rest of the code is left as an exercise for the student. :stuck_out_tongue:

I like the idea of looping a short section of the animation. That would work well as long as all your tracks are uniform visual copies.

This is pretty ridiculous, my internet can not find that website! Could you paste that article here?

This is NOT my article, I just wanted to make that clear.
ORIGINAL ARTICLE: http://simonschreibt.de/gat/lego-batman-crawler/

LEGO is awesome. LEGO games are awesome. And – at least for me – this trick is awesome. It’s about the crawler “chains”. You know, the things around the wheel rims.
http://data.simonschreibt.de/gat036/blog_crawler_02.gifSource: LEGO Batman

Let me explain, why i think this looks really good: If you wanna do such a “conveyor” animation in 3D, you need to animate some geometry. And depending on your engine you can do this in different ways:
Way #1 “Texture Animation”
You could use a texture animation where you let a texture slide over a geometry. This is very easy to setup but the silhouette of the whole thing isn’t that stunning:
Way #2 “Geometry Animation”

If your engine doesn’t support texture animation and/or you want a nice silhouette you can make a conveyor out of separate geometries. This costs a lot more animation effort and of course more drawcalls since you get more separate objects. The plus side: the silhouette looks more interesting.
http://data.simonschreibt.de/gat036/blog_max_crawler_02.gifFor this, every “plate” just moves one “step” forward and then the animation starts again. You can see this better in the following animation where the plates “jumps” back when they reached their final position. Every color marks a single object.
The LEGO Way

Let’s look again at the LEGO thingie. Am i the only one who thinks, that this looks like they bent a rubber geometry around the wheel rims? I really like it!

http://data.simonschreibt.de/gat036/blog_crawler_01.gifSource: LEGO Batman

At first i thought about crazy bend-modify-programmer-stuff but then i checked out the drawcalls/wireframes. I bet you already guessed how they did it. If not, here’s a clue:
http://data.simonschreibt.de/gat036/blog_crawler_wire_01.gifSource: LEGO Batman

It’s kind of a mixture of both ways.
There’s a big geometry as a base (without crazy silhouette) and in addition several moving smaller parts (which create a great silhouette). Of course you don’t need a texture animation on the base geometry because there’s no visible texture/structure but it gives the whole thing a good shape.
http://data.simonschreibt.de/gat036/blog_max_crawler_04.gifhttp://data.simonschreibt.de/gat036/blog_max_crawler_05.gifWith that, they achieved this really cool bended rubber look which i really like. To be honest, i think most people figured out the trick immediately, but personally i wasn’t sure until i saw the wireframe and the separate drawcalls.

Good work, Traveller’s Tales. http://simonschreibt.de/wp-includes/images/smilies/icon_smile.gif

Update #1
Thanks to Aurelio (from the comments) who mentioned an interesting thing called “Sub Pivot Point Baker”. Something like this is available in UDK and also packed into these very good looking tools. With that it seems to be possible, to have only one geometry but with different sub-geometries/elements/parts and everyone of those has it’s own pivot point which would save some draw calls if you would use it on stuff like the crawler.

Okay, now I just need to know how to make a tank track anim without curves. Anyone know how?