Help with force calculations for raycast suspension system

I’m trying really hard to learn how to make a raycasting suspension system because I know the end result will be really good and worth it, no matter how long it takes. But I’ve spent almost a whole day just trying to figure out the first part and I don’t know how to do it. This uses 4 thrusters on each corner of the vehicle with VectorForces in them.

I understand how this system works due to this video, it’s good: Space Dust Racing UE4 Arcade Vehicle Physics Tour - YouTube

But, my problem is calculating the amount of force to use on the thrusters in each corner to keep the car level.

This whole day I’ve been trying to figure it out, and got nothing. This is pretty frustrating

I’ve gone through trying a bunch of different equations and this is the last one I tried to use before coming to the forums:

local thrusters = car.Thrusters:GetChildren()

local weight = 0

for _, part in ipairs(car:GetDescendants()) do
	if part:IsA("BasePart") and not part.Massless then 
		weight += (part:GetMass() * workspace.Gravity) -- gets the total WEIGHT of the car
	end
end

print(weight)

local susHeight = 2
local rayLength = 10

local function updateThruster(thruster)
	local origin = thruster.Position 
	
	local hit, pos, normal = raycast(origin, thruster.CFrame:VectorToObjectSpace(Vector3.new(0, -1, 0) * rayLength))
	
	if hit and hit.CanCollide then 
		local distToGround = (origin - pos).magnitude 
		
		local suspensionDist = susHeight - distToGround
		
		--print(distToGround, hit.Name)
		
		thruster.Thrust.Force = Vector3.new(0, suspensionDist * (weight/#thrusters), 0)
	else
		thruster.Thrust.Force = Vector3.new()
	end
end

This gives me this:

Which is surprisingly the closest I’ve gotten to keeping it level : (
My character is massless as well, set by a server script. Is anything else affecting the weight?

All of the articles I’ve seen don’t really give a lot of information on how to do this. Can someone please help, and also walk me through why so that I understand it? And if you don’t mind, how would I incorporate spring damping equations into this?

1 Like

Hmm, comparing with this post on suspension physics.

I’d say your equation is lacking…

This is your force equation in the y axis

suspensionDist * (weight/#thrusters)

This is his.

local f = a*x + b*(x-ST.dx) + b/2*(x-ST.d2x) --Use the equation

Consequently, yeah I believe you are missing maths and the most important part of the equation which you are missing is rigidity which requires differentiation maths. In his equation rigidity factor b btw which is being multiplied with the derivative. Currently, I believe your car in the video is not rigid and hence keeps bouncing up and down. Perhaps this should fix it?

1 Like

I tried using that but it looked like it wasn’t strong enough to push up my vehicle, unless I implemented it wrong. How would I calculate the right amount of force with this equation?

According to more research going down the rabbit hole lol in this post.

you need to multiple small f with the weight in order to make it stronger.

BF.Force = Vector3.new(0, f * (Mass / #Thrusters * 2), 0)
1 Like

Is this for an actual car, or a hovercraft?
If it’s for a car then don’t worry about keeping the car level since this would be unrealistic. If a car runs over a bump with one wheel the car doesn’t stay level, the corner driving over the bump lifts up due to the suspension spring.
Also, are all the Parts in your Model Massless? If so then that makes your weight=0 and in your equation 0/#thrusters would equal an error.
I’ve had good luck with using the Constraint Roblox suspension:
https://www.roblox.com/games/534616891/Tracked-vehicle-Suspension-tests

I tried that too, but it ended up being too strong.

#1 Why is it the mass / #thrusters * 2?

I need to be able to get the perfect amount of force such that the vehicle won’t be flung in the air or stuck to the ground, while at the same time maintaining its suspension height (e.g. 1.5 studs) and still having springs in it react to outside forces.

I’ve actually made a completely fully functional suspension chassis using springs and prismatics (finished it yesterday, worked on it for about a week), with every feature I wanted like acceleration, braking, drifting, nitro, etc but the overall experience and handling of scripted suspensions are WAY smoother and scripted suspensions handle things like terrain and high speeds 100x better. Sure the constraints can be more realistic but they do not have very good handling and driving with them isn’t really smooth, or at least they’re not as good as scripted suspension. That’s why I’m determined to learn this and not back down to a suspension chassis simply because creating a scripted suspension is “too hard”

1 Like

Try the cars in my place, I think you’ll be surprised how well they work when tuned properly.
The dune buggies and F1 cars have double wishbone suspensions, and the army truck uses CylindricalConstraints for steering and PrismaticConstraints for the rear wheels. If you click the gearshift area the top speed is approximately doubled.
I used the double wishbone suspensions just to see how easy/difficult it would be. Turns out it wasn’t that bad.

1 Like

Alright, I’ll try them. Thanks

Oh yeah I forgot to mark this as solved. My problem was that I didn’t have any damping on the spring. Plus, I switched to a different equation to calculate the force. I combined my new code to calculate force and used the damping equation in the free model jeep and it works perfectly. Just make sure to fine tune.

Could you share some code? I have the same problem, I did several implementations (including PID Controller) but nothing good so far.

I’ve made a hovercar very recently. The code is rushed (I feel so disgusted from even a glance) and the functionality is incomplete; no air resistance and movement seems to be choppy (can’t figure out why). You should still be able to see how the math works despite this. Hovercar Test v2 - Roblox (unclopylocked)

2 Likes

Thanks. I’m doing an implementation based on this project GitHub - mrgarcialuigi/ArcadeVehicleController: Custom vehicle physics for arcade-style games, made for Unity, which is based on the Space Dust Racing video

2 Likes