Scripting a car system

I am trying to learn how to make a car system. The car should have suspension, and shouldn’t lag or bug out. [Jailbreak kind of cars.] I don’t want to use roblox springs or a roblox vehicle seat. [If it’s easier to use the vehicle seat let me know] I want to be able to customize it in scripts completely. I am by no means bad at scripting, I am very experienced but I am new to making vehicles. I just need some help.

So I’ve been reading this post: Car Suspension (Scripted) - #6 by Oseday on how to make the vehicle.

So when the player presses E, they will enter the vehicle and the controls will be loaded into them. All of that is easy for me, I just can’t get the car physics down and I have been reading lots of stuff on it but I don’t get it.

Here is the picture of what I’m working with:
Car picture

I am wondering about how the forces and the wheels work. I have read the post quite a bit but I have a hard time understanding it and it’s hard to figure out any other methods of learning how to make cars.

What I’m thinking: The wheels have can-collide off. There are body thrusters on all 4 corners of the car. Do they push the car up or down? Are they what keep the car in the air? How do the wheels move up and down with the car but look like they have suspension so it couldn’t possibly be a weld/motor/hinge. Do the wheels use another kind of weld or are they being CFramed constantly using a raycast to track the distance to the ground? What body mover do I use to make the car move forward/backward and turn and how do I get the wheels to turn?

I don’t really need code, I pretty much need explanations because I am super confused.

1 Like

They push it up.

Yes.

Yes it raycasts downwards to the ground. The wheel model’s Motor6D CFrame is constantly being set.

Put a force and torque into the body of the car. They will move and turn it.

1 Like

So right now I am trying to create the floating chassis with a simple block before I add the wheels. I have 4 body thrusters, and I put a attachment in every corner so that I could find the locations for the body thrusters. Correct me if that’s the wrong way to get the locations.

How I incorporated your code into it. Trying to update thrusts nonstop.:

local MainPart = script.Parent --The part that has the attachments, and thrusts in it
function runSuspension()
	local d = 4 --How high I want the part to be
	
	local a = 1.8 --Stiffness, higher means higher height at suspension
	local b = 0.6 --Rigidity higher means the suspensions will get less effected by slight changes and will balance out unlike Roblox's suspensions. This is the part that dampens the suspension.
	
	local ST = {dx=0,d2x=0} --For storing the derivatives per suspension
	
	for i = 1,4 do --For every suspension, in this case 4 of them
		local RayOrigin = MainPart["Attachment"..i].WorldPosition
		local RayEnd = Vector3.new(RayOrigin.X,RayOrigin.Y-15,RayOrigin.Z)
		local ray = Ray.new(RayOrigin, RayEnd-RayOrigin)
		local hitPart, hitPosition = workspace:FindPartOnRay(ray, MainPart)
		local distanceToGround = (RayOrigin-hitPosition).magnitude --Finding the distance to the ground. Tested it and it works.
		
		local x = d - distanceToGround --X is how much the suspension is contracted
	
		local f = a*x + b*(x-ST.dx) + b/2*(x-ST.d2x) --Use the equation
	
		ST.d2x = ST.dx --Store the past values
		ST.dx = x
	 
		script.Parent["BodyThrust"..i].Force = Vector3.new(0,f,0) --Apply the forces
	end
end

while true do
	runSuspension()
	wait()
end

Is this the correct way to do suspension_length and suspension_distance? Is there anything I am missing to achieve the floating chassis.

Currently my problem is that the body thrusters don’t have enough force to keep the part up. Also, even though the part is completely flat on the baseplate, the 4 bodythrusters have different forces. One corner has 7.8, and another corner has 5.2. I tested out my distanceToGround code by printing it, and all 4 corners are the same even when I move the part up and down.

1 Like

dx and d2x are supposed to be variables of the wheels not the car.

Thank you. What code would I use to get the force for the thrusters then? I have all 4 thrusters in the corners of the part and I find the distance to the ground every loop. What would I do to get the correct force necessary to hold the part up in the air?

1 Like

Please note that workspace:FindPartOnRay and Ray.new is deprecated, use RaycastParams | Documentation - Roblox Creator Hub instead

I know this is an old topic, however just wondering if this was ever solved. Have you found a solution to this? Thanks

No I never solved that. I did however eventually create a good car with this Roblox: Car Rig Tutorial (Part 1 - Setup) - YouTube.

See my car here. It’s the jeep without the fire.- Unkown - Roblox

I customized/improved it quite a bit to my liking and added some stuff.

1 Like