- Home /
Tank Track Treads
Heya there!
How can I have tank treads running around a certain amount of wheelcolliders? I have Googled the whole internet without anything to help. I already used Blender with weight painting but that isn't perfect
So now I wan't to try having a object running around wheelcollider.
If you need more info, look at the image. It's hard to explain. https://imgur.com/5tgS2f7
Thanks!
Answer by Klarzahs · Sep 22, 2021 at 12:23 PM
Hi @Jesse2431
Personally i would do it with a custom mesh.
You can get the outer points of each collider (angle x size x vector3.up), create a mesh between them. Then create a texture for the tracks that can loop, so that each of the track-mesh-triangles can use the same texture.
Then you can mimic the track movement/rotation by simply offsetting the UV coordinates.
You could either update the mesh information each frame, or (what i would recommend) is writing a custom texture shader in which you only have to increase the offset
Can you provide a little code? I need a little push into the right direction.
Sure. You would have to create quads, each between two wheels. You can get the vertex position for that by starting from the collider position (transform) and size. To get the "correct" direction, you would have to rotate the up vector around the right vector of the wheel. Have a look at Quaternion.AngleAxis. The angle depends on the wheel, as its not always straight down (which would be -Vector3.Up). The wheel in front would have a slightly forward position, the wheel at the back a slightly backwards position.
Now for the shader. If you haven't used them before, forget about them and update the mesh's UV positons each time. As the mesh is relatively small it shouldn't affect performance too much. Hope that helps
Your answer