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 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:
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.
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.
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?