Help needed with animating tank tracks

Hello, im making a tank game and while i have tracks that work, they dont look good as they are just parts that deform at points to make them look like tracks.
And i want to add some animation to my tracks.
I want it to look simalar to the tracks of Steel Titans or MTC4 but i have no idea on how to make such tracks/animation

Current tracks:

Example Video:

6 Likes

i think they’re just using a bunch of hinge constraints, not sure

1 Like

I dont think so as that would be really laggy and ive seen the code for the track system in MTC4 but i cant really understand it/how its doing the tracks

1 Like

Try using Bones to animate the parts without lag spikes.

1 Like

Just had an idea, is there a way for a part to follow a path? If yes i could just “model” the path and make deforming parts so the tracks react to the “wheels”. I have searcher around but havent found anything yet

1 Like

There are a number of ways to approach this problem, with and without using Roblox physics. In general, most games with realistic real-world tanks that have 90+ links per track, are using skinned meshes and bones to render the tracks. It’s simply too many links to do with Roblox parts and hinges. Even if you can get the simulation itself to be stable, it’s too many part changes to replicate per frame.

Steel Titans is definitely using bones, and client-side rendering. It’s a pretty big clue that your own tank is the only one you see with animated tracks; all the other tanks just have non-animating black bands around the wheels. War Thunder also has skinned mesh tracks on the tanks, and they do plenty of cheats to get good performance that you can spot if you look closely.

When I made a tank in Roblox, I also used skinned mesh parts and procedural (purely scripted) animation:

Here’s the thing though:this is not an easy coding problem. The solver I wrote to position the track links is fairly complex. It runs every frame, starting with considering the positions of all of the wheels the tracks go around and using a modified convex hull algorithm to find the path around them in terms of a closed-loop spline of line segments and circular arcs. Then, some raycasts to the ground are used to see if there are any points between the wheels where ground obstacles are pushing up on the tracks to make the path convex. Because of how tank wheel bogies can move, the tracks aren’t always in contact with all of the ground wheels, some get skipped.

The resulting spline is a taut path around the wheels, which is not a final solution for a few reasons:

  1. Real tank tracks are made from rigid links, so there is an overall path length constraint that needs to be satisfied, which is done in my renderer by letting the track sag over the return rollers.
  2. The tracks have a discrete number of links, but the spline path is a continuous curve. The spline needs to be converted to a polygon of only line segments, one per link.
  3. The path alone is not the whole problem, there is a sprocket driving the track which determines the phase. The links have to always line up with the sprocket teeth.

Overall, there isn’t a closed-form solution to this, the solver is iterative. In practice though, there are usually enough links in the tracks that the discrete polyspline is close enough in length to the continuous spline path that sagging can take up the slack, and the amount of sagging can be done with a non-iterative solution (although that’s not always what I’m doing). In the latest version, I replaced my original circular arc sagging with gravity-direction-accurate catenary sag, and this is another iterative solving step:

None of this is easy math. I don’t know about the Steel Titans devs, but I have engineering and math degrees and it’s still a challenge to get these sort of things working and performant in Lua. There are some custom algorithms and numeric root finding involved, along with a lot of line-line and line-circle intersections, even some calculus for the catenary parts. Despite being on Roblox, both Steel Titans, and my own tank are both a bit more accurate that what’s done in either War Thunder or World of Tanks. For example, I never cheat the length constraint solve by distributing error over the link gaps. You could do this, but not if you want the links to exactly track with the drive sprocket and never exhibit any noticeable spacing changes.

That said, there is another option. Instead of a raw Lua solver, you could also model the tracks with a smaller number of parts and hinges, physically simulated, but then make the physical parts invisible and just use their positions each frame as sample points, which you can then interpolate between to position rendered track links.

Some games also use beams or animated textures on non-deforming meshparts. Obviously this is not going to look as realistic as individually rendered PBR links, but it depends on what look you’re after. If you aren’t concerned with showing moving links at all, you could just basically use a skinned mesh part to make a sort of deformable rubber band around the wheels. In Roblox, Bones are actually just special Attachment instances, so you can put them on the edge of non-rotating, invisible, frictionless “wheels” so that you don’t even need scripts to drive the deformation. It all depends on if you want tracks that actually look like they have moving links.

11 Likes

I had the same idea but idk how to interpolate the tracks position, i already have the physical parts/deforming parts.

2 Likes

The most standard approach would be to use the physical part positions as the knots of a cubic spline. But you still have to do an arc-length re-parameterization of the spline because of how the links need to be evenly spaced.

A much easier approach still, if you’re OK with the number of visible links being at most 2X the number of physics ones, then you can just do linear interpolation between them. It won’t be as nice smooth curve, but it might be good enough, depends on the look you’re after.

2 Likes

Well it only needs to work and look better than this, could you help me set your method up?

2 Likes

In the method you linked, I used textures, while changing offsets. The track model was a transparent set of parts shaped like a tank track, completely stationary, simply welded to the hull.

The attempt was a big failure in general, I am still trying to solve it. If I were you I would completely give up trying to make it physics-based, since it’s really laggy. Popular games such as War Thunder use texture animation for their tracks instead of physical movement

2 Likes

well i dont want it to be completly physics based, i just want it to look like it was because its so laggy

2 Likes

I guess you could make the track animation texture-based, and the tracks reacting to the suspension physics based, like this

1 Like

I already have the deforming tracks, i just need the animation

1 Like

You can use the animation editor and use IK to link the tracks to the wheels.

PS: Please get back to me if you found a solution to your problem!

4 Likes