Procedural Tank Tracks

Procedural Tank Tracks

A Simple way to Create Basic Procedural Tank tracks

Features:

  • Generate Tank Tracks from Wheel Layout
  • Easy and Fast setup
  • LOD System
  • Client Side only

Showcase:


Usage:

Heres a script Example on how to use it:

--Local Script
local TrackRenderer = require(game.ReplicatedStorage.Modules.TrackRenderer)

local tracksettings = TrackRenderer.newsettings() --Create Settings
tracksettings.TrackLength = 1 --Determines the Length of each Length of the Tread
tracksettings.TrackModel = game.ReplicatedStorage.Tracks.SimpleTrack --The Model to use
tracksettings.ParallelLua = false --use Seperate Actor and Script for each Tracks (Delays)
tracksettings.LowDetailPartWidth = 3 --Set the Width of the Part
tracksettings.LowDetailPartHeight = 0.3 --Set the Height of the Part
tracksettings.MiddleTrack = nil --place parts in between the treads

local track = TrackRenderer.new(tracksettings, v:GetChildren()) --track Constructor
        
track:Render() --Render the Track
track:SetSpeed(0.05) --Sets the Speed (In Studs/s)

Wheel Layout Setup:

we have to name the wheels numerically so the code knows which wheel to use.
The direction in which the Order follows must always have the Top be facing the Desired direction and the Bottom be opposite.


and we must add “_curve” to let the code know that the wheels “curves” around, in this case its 2. 4, 1, 5.

example wheel: Wheels.rbxm (4.3 KB)


API:

TrackRenderer.newsettings(): TrackSettings 

Returns a TrackSettings which would later be passed on to the TrackRenderer Constructor

  • Properties:
TrackSettings = {
    TrackModel: Instance,
    TrackLength: number,
    ParallelLua: boolean,
    LowDetailPartWidth: number,
    LowDetailPartHeight: number,
    MiddleTrack: Instance,
}
  • TrackModel: Instance
    The Model or Part to use

  • TrackLength: Number
    The Length of each Tread

  • ParallelLua: boolean
    Creates an Actor just for that Track, allows for Parallel luau

  • LowDetailPartWidth: number
    The Width of the Low Detail part

  • LowDetailPartHeight: number
    The Height of the Low Detail part

  • MiddleTrack: Instance
    Places a Different set of Treads in between the Original Treads


TrackRenderer.new(settings: TrackSettings, wheels: {Instance}): Track

Creates a new Track Object with the Settings from the TrackSettings and the Table of wheels

Methods

  • track:SetSpeed(number)
    Sets the Speed.

  • track:SetLODDistance(number)
    Set s the distance where the LOD will activate

  • track:Render()
    Renders the Track

  • track:StopRendering()
    Stops Rendering the Track

  • track:Destroy()
    Destroys the Track

Properties

  • track.Wheels (Read-Only)
    The wheels currently used by the track (Includes the Main Part).

Installation:


you can either get it from:

or download the showcase place
showcase.rbxl (95.1 KB)

40 Likes

Amazing work! Will definitely be using this in the future.

1 Like

I love you ⁱ ˡᵒᵛᵉ ʸᵒᵘ ˢᵒ ᵐᵘᶜʰ ⁱ ˡᵒᵛᵉ ʸᵒᵘ ˢᵒ ᵐᵘᶜʰ

1 Like

this is very good work, I’ll be crediting you in my game

1 Like

How do i make the track speed relative to the tank’s speed? like on a chassis.

Overall a greater and simpler model than the previous one

1 Like

get the rotational speed and turn them into how fast the wheels are going in that one direction, then just average them all out. like this

for i, v: BasePart in ipairs(track.Wheels) do
	if v.Name ~= "Main" then
		local actualwheelpart: BasePart = v:GetJoints()[1].Part0.Parent.Wheel
		--or the actual wheel part thats spinning

		if actualwheelpart.Parent.Name == "DriveWheel" then
			local dot2 = vector.dot(actualwheelpart.AssemblyLinearVelocity, v.CFrame.LookVector)

			local spd = (actualwheelpart.AssemblyAngularVelocity.Magnitude * (actualwheelpart.Size.Z/2)) * math.clamp(dot2, -1, 1)
			table.insert(data, spd)
		end
	end
end

local totalspeed = 0
for _, v in ipairs(data) do
	totalspeed += v
end
totalspeed = totalspeed/#data
track:SetSpeed(totalspeed)
2 Likes

Procedural Tank Tracks Version 1.0.2

  • Fixed an issue where some numbers could become ‘NAN’
  • fixed minor code issues
  • fixed issues from the version 1.0.1 release

Downloads

6 Likes

this is an absolutely phenomenal post. I have been looking for something like this for explicit use on skidsteers and excavators without resorting to physic tracks. They make those machines laggy for users without a good pc

will be definitely getting a place in my credits!

1 Like