Today I want to tell you about a technique I have discovered for making vehicles with tank style turning using vehicle seats. I have done a search and couldn’t find a tutorial on this, despite how easy it is to accomplish!
This tutorial assumes you know how to create objects including parts, welds and hinges, scripts, models and of course the vehicle seat.
Traditionally vehicle seats can be used for conventional cars where one set of wheels pivots side to side for steer and the other set of wheels provide drive. What I’m about to describe will make a vehicle that can turn on a pinhead like a tank by allowing the wheels on each side to drive in opposite directions.
To start off you will want to create four cylinder parts, one block part and your vehicle seat.
Weld the vehicle seat to the top of the block part and use four hinges on the block part to attach the cylinder parts, one on each so the block part forms the body and the cylinder parts form the wheels. Pop your creation into a model to create a result like this:
That is the modelling of the car done. You’ll notice we have also created a script inside the vehicle seat. This is where the magic happens:
-- First up define your parts local seat = script.Parent local car = seat.Parent local leftDrive = car.Body.LeftDrive local rightDrive = car.Body.RightDrive --You might have noticed a couple of hinges called left and right steer in the car model. These are just free spinning hinges and don't need defining in this script. -- Define your variables local maxSpeed = 10 -- Down bottom we've added a line which will trigger a function when the seat's controls are altered. -- And here is that function. We've called it 'onChanged' local function onChanged (property) --This first 'main if' will do two things. if property == "Steer" then --This first 'sub if' will cause the vehicle to turn left or right depending on input. if seat.Steer > 0 or seat.Steer < 0 then leftDrive.AngularVelocity = maxSpeed * seat.Steer rightDrive.AngularVelocity = maxSpeed * seat.Steer end -- second 'sub if' will restore the wheels drive back to normal after the player stops attempting to steer. This is important if the player wants to continue to drive forwards or backwards after stopping steering. if seat.Steer == 0 then leftDrive.AngularVelocity = maxSpeed * seat.Throttle rightDrive.AngularVelocity = -maxSpeed * seat.Throttle end end -- This second 'main if' simply drives the vehicle forward or back depending on input if property == "Throttle" then leftDrive.AngularVelocity = maxSpeed * seat.Throttle rightDrive.AngularVelocity = -maxSpeed * seat.Throttle end end seat.Changed:Connect(onChanged)
The trick to getting this to work, is to use seat.Steer as a proxy for seat.Throttle when you want to make your vehicle turn. Notice when making the vehicle drive forward or backwards, to ensure the right Drive wheel is turning in agreement with the left, it needs to be turned into a negative number.
Make sure your parts can collide, aren’t anchored, hit test, report your results!
robloxapp-20201016-1900354.wmv (6.0 MB)
Be gentle, I’m new.