Some time ago I posted about a small spline-based tank tracks system that I’d built.
Because some people asked me personally if they could download it, I decided to do some more work on the code and to create a free package with the updated tracks system and a small demo scene.
In the package:
- Curves and Splines scripts from CatlikeCoding.com : https://catlikecoding.com/unity/tutorials/curves-and-splines/TrackCreator Script to create your own tracks with during Play mode. The TrackCreator script takes in a prefab of a Single track piece and clones it around a Spline but it can also be setup with for instance two different track pieces so that you can add a second prefab for the links between the main trackpieces.
Created tracks can be copied during Play mode and pasted back into the Hierarchy outside of Play mode, after which the Track Creator script can be disabled or removed, this will cause less delay when starting the Player but is optional.TrackDriver Script that controls the motion of a singular tank track created with the TrackCreator. The TrackDriver script holds a list of references to the single track piece items created with the TrackCreator and drives them around the spline. The motion of the track is controlled by the speed variable of the TrackDriver component.TrackedVehicleController Script that takes input from the player via the Horizontal and Vertical axis (WASD or Arrow keys) and uses it to drive two TrackDriver components, one for the left and one for the right track. The TrackedVehicleController also stores references to the left and right wheels of the tank tracks to drive their speeds synchronous to the moving track piece items.
- Three pre-made generic tanks to show how the system works with tanks of different widths, thin, normal and wide. Because the motion of the tracks has to be synchronised to the speed of the vehicle and is also dependant on the width/radius of the vehicle. You can simply duplicate one of the generic tank prefabs and change the geometry of the Meshes to your own tank design.
The Prefabs can be dragged into any scene from the Prefabs folder to make clones of them.
- DemoScene with the three Prefab tanks added to the Hierarchy.
If you like this package then let me know, maybe then I’ll continue to improve it and to add functionality to it. Also if you find ways to improve upon it and to make the system more accurate then also let me know, because I would love to know how:)
For now I’ve tried to make the code as simple and self-explanatory as possible.
The .unitypackage below contains scripts for generating splines, tracks and for controlling a tracked vehicle. Have a look in the included demo scene to see how the system works with vehicles that have different widths.
BUY ME A COFFEE
Donate $5 to buy me a coffee so I have the fuel I need to keep producing great tutorials!
Can you provide a little documentation or tutorial? I find it difficult to use to be honest
I will see what I can do tomorrow but I’m busy with some things at the moment so I can’t promise anything. Maybe you can look around for some tutorials on youtube about splines and spline walkers because it is based around that system. You can also add me on discord and ask questions there if you like : Timanious#0424