How to Rig a Car

Thank you! Really appreciate you taking the time to help

1 Like

Np. Just keep in mind that since itā€™s a sphere, it will be sticking out of the sides of the car, and there is really no method (That I know of) to fix this.

I just wanted to try it out both ways to see what worked better on my game. Thanks :slight_smile:

1 Like

You need to play with the CylindricalConstraint settings and make the turn speed something like 2-5 to make the steering smooth. I also recommend changing with the cars mass.
Trail and after trial until you reach what you want!

I tried messing around with the different CylindricalConstraint settings for a while, which ones do you mean exactly? and do you increase them/decrease them?

You are a godsend my friend. This is amazing, thank you so much. You were so detailed in everything and the way it worked. I can now say that I can rig and script a car on my own thanks to this. Thank you so much again. Loved it. :smiley:

This post is when i learnt that i could use a cylindrical constraint instead of using another part to join the spring and the prismatic constraint to the wheel with a hinge constraint. This method is so much better as the weels dont seem to glitch. :slight_smile:

Hello so i have a problem in the third part, my code dosent work i tried to rewrite it a lot of times but still wrong, can someone help me?

 local car = script.Parent
local seat = car.Body.VehicleSeat
local body = car.Body.Body

local physicsService = game:GetService("PhysicsService")
local defaultCollisionGroup = "Default"
local characterCollisionGroup = "Character"

local cooldown = 0

local occupiedPlayer


local function Cooldown(durantion)
	local cooldownTag = tick()
	cooldown = cooldownTag
	delay(durantion, function()
		if (cooldown == cooldownTag) then
			cooldown = 0
		end
	end)
end


local function SetCharacterCollide(character, shouldCollide)
	local group = (shouldCollide and defaultCollisionGroup or characterCollisionGroup)
	for _,part in ipairs(character:GetDescendants()) do
		if (part:IsA("BasePart")) then
			part.Massless = not shouldCollide
			physicsService:SetPartCollisionGroup(part, group)
		end
	end
end


local function BodyTouched(part)

	if (seat.Occupant or cooldown ~= 0) then return end

	local character = part.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	if (not player) then return end

	local humanoid = character:FindFirstChildOfClass("humanoid")
	if (not humanoid) then return end

	seat:Sit(humanoid)
	occupiedPlayer = player
	SetCharacterCollide(character, false)
	car.PrimaryPart:SetNetworkOwner(player)
	Cooldown(1)

end


local function OccupantChanged()
	if (seat.Occupant) then return end
	if (occupiedPlayer.Character) then
		SetCharacterCollide(occupiedPlayer.Character, true)
	end
	car.PrimaryPart:SetNetworkOwner(player)
	occupiedPlayer = nil
end


body.Touched:Connect(BodyTouched)
seat:GetPropertyChangedSignal("Occupant"):Connect(OccupantChanged)

Just a question,

Will it lag if a bunch of vehicles are driving around?

Great Tutorial! Really well explained and detailed, it would be awesome if there was a continuation, where you show us how to add more stuff to the car gauges, turning signals, etc.

I donā€™t think so, i might be wrong. The script transfers network ownership to the local player but you can still lag when you have a LOT of them, depends on your pc specs.

Your missing a lot of code from the tutorial idk if you followed the whole tutorial but this was the final code:

local car = script.Parent
local seat = car.Body.VehicleSeat
local body = car.Body.Body

local physicsService = game:GetService("PhysicsService")
local DefaultCollisionGroup = "Default"
local CharacterCollisionGroup = "Character"

local cooldown = 0

local OccupiedPlayer
local OccupiedClientScript

local carClientScript = script.CarClient

local function Cooldown(duration)
	local cooldownTag = tick()
	cooldown = cooldownTag
	delay(duration,function()
		if (cooldown == cooldownTag) then
			cooldown = 0
		end
	end)
end


local function SetCharacterCollide(character,ShouldCollide)
	local group = (ShouldCollide and DefaultCollisionGroup or CharacterCollisionGroup)
	for _,part in ipairs(character:GetDescendants()) do
		if (part:IsA("BasePart")) then
			part.Massless = not ShouldCollide
			physicsService:SetPartCollisionGroup(part, group)
		end
	end
end

local function BodyTouched(part)
	
	if (seat.Occupant or cooldown ~= 0) then return end
	
	local character = part.Parent 
	local player = game.Players:GetPlayerFromCharacter(character)
	if (not player) then return end
	
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if (not humanoid) then return end
	
	seat:Sit(humanoid)
	OccupiedPlayer = player
	SetCharacterCollide(character,false)
	car.PrimaryPart:CanSetNetworkOwnership(player)
	OccupiedClientScript = carClientScript:Clone()
	OccupiedClientScript.Car.Value = car
	OccupiedClientScript.Parent = player.Backpack
	Cooldown(2)
end

local function OccupantChanged()
	if (seat.Occupant) then return end
	if (OccupiedPlayer.Character) then
		SetCharacterCollide(OccupiedPlayer.Character,true)
	end
	if (OccupiedClientScript.Parent) then
		OccupiedClientScript.Stop.Value = true
		local client = OccupiedClientScript
		delay(3, function()
			client:Destroy()
		end)
	end
	car.PrimaryPart:SetNetworkOwnershipAuto()
	OccupiedPlayer = nil
	OccupiedClientScript = nil
	Cooldown(3)
end

body.Touched:Connect(BodyTouched)
seat:GetPropertyChangedSignal("Occupant"):Connect(OccupantChanged)

Iā€™m running into an issue with this car chassis setup. The car works great on laptop/desktop, and even works great on my Samsung Galaxy Note 9. However, the steering seems to be really odd on any Apple mobile devices. When you attempt to drive straight, the car will be turning. The controls are pretty sensitive on my Samsung phone but itā€™s not unbearable like it is on an iPhone.

Part of me thinks this is more of a Roblox issue, though I am not noticing this issue on other games. Is it possible Roblox is returning some weird numbers for my VehicleSeatā€™s SteerFloat for iPhones?

Hereā€™s a link to my thread which gives a better outline of my problem, including a video:

If anyone knows what I can do to fix this, it would be greatly appreciated.

1 Like

The tutorial is super good! Keep up with your work! :grinning:

I donā€™t quite understand a few things and am need help with trying to make a drift button for a car chassis Iā€™m making so far this is the code Iā€™m using but it doesnā€™t seem to quite work that well. Also Iā€™m needing help calculating suspension based off the mass of the car. I decide the mass of the car using a weight brick which I change the density using a formula. The suspension is the main thing I cant figure out also how would you recommend calculating how much density a car brick of 1x1x1 volume should have to equal 1 pound I need the suspension to match the density, and Iā€™ve tried everything I can think of

--Suspension
local SuspensionC = Instance.new("SpringConstraint", Folder)
SuspensionC.Name = "Suspension"
SuspensionC.Damping = SpringDamping
SuspensionC.MaxForce = math.huge
SuspensionC.Stiffness = SpringStiffness
SuspensionC.LimitsEnabled = true
SuspensionC.MaxLength = 3
SuspensionC.MinLength = 0
SuspensionC.FreeLength = 2

local SuspensionPC = Instance.new("PrismaticConstraint", Folder)
SuspensionPC.Name = "Suspension"
SuspensionPC.LimitsEnabled = true
SuspensionPC.LowerLimit = 0
SuspensionPC.UpperLimit = 0

-- Drift Script
local function DriftOn()
if VehicleSeat.AssemblyLinearVelocity.Magnitude/Stats.SpeedMultiplier.Value> Stats.MinimumDriftSpeed.Value and math.abs(VehicleSeat.SteerFloat) >= 0.2 then
UsingDrift = true
Drift.AngularVelocity = Vector3.new(0,DriftVelocity* (-VehicleSeat.SteerFloat/math.abs(VehicleSeat.SteerFloat)),0)
Drift.MaxTorque = Vector3.new(0,Force,0)
for i,Wheelz in pairs(Model.Wheels:GetChildren()) do
Wheelz.CustomPhysicalProperties = PhysicalProperties.new(0.3, 0.36, 0, 100, 100)
end
wait(0.1)
Drift.AngularVelocity = Vector3.new(0,0,0)
Drift.MaxTorque = Vector3.new(0,0,0)
end
end

Iā€™ve always found it easier to read this way I apologize for my weird habits.

Iā€™m stuck on Part 2. My frontal wheels keep glitching upwards. If I do anything, that influences the suspension (falling, rolling down the wedge) the frontal wheels just break.

If I move it downwards, so itā€™s inside the Baseplate, it glitches back up, but with the wheels (sometimes) fixed.

(Note: My car, has multiple meshes, but all set up correct I guess)

Before (already simulating)
image

After letting it fall
image

After letting it roll downhill
image

You should add limits to the cylindrical constraints.

I tried using it, works now. Is this how you intended it to look like?
(the yellow numbers are just the Limits)

Yeah. But why do the springs look slanted?

EDIT: Make the upper limit / lower limit the bottom of the floor of the car, like where the 0 is.