I’ve been losing sleep over this problem for about a week now: I have a raycast suspension car that when going up inclines at high speeds “sinks” into the ground, and I have no clue how to counter it.
Low speed:
High speed:
Things I have tried:
-several other raycast suspension methods
-adding more attachments for spring forces
-maxing out the damping and stiffness
-multiplying the suspension force by the car’s UpVector and the ray’s Normal
-using a PID controller
The closest thing I found to a solution was using AlignPosition (casting rays from 4 corners to get the average ground position) to keep the car elevated above ground, however that brings with it its’ own set of problems.
Yeah, that’s what I used the AlignPosition for, however I would prefer to keep the car elevated using just Forces. As for the frequency of raycasts, they run on the RenderStepped event, so I highly doubt it.
I’m not sure if it matters, but you should probably use Heartbeat as that’s tied with physics framerate. I think AlignPosition is probably just too slow, which is why I recommend coding in the offset directly.
I tried Heartbeat too, same issue still happens.
The AlignPosition works good, but my main problem with it is that in order to use it I would need to simulate a lot of car behavior that happens naturally when using VectorForces.
I don’t see why it would interfere with physics. All you need it to do is move the car with the relative distance from the raycast in order to offset it enough to get rid of the clipping.
This didn’t really help the problem + I had to use AlignPosition for this instead because when I tried to change the position of the car, only the children of it would move for some reason
As I mentioned before, I would be using AlignPosition right now if it weren’t for the fact that I would need to simulate some car behaviors that would happen naturally if I used VectorForces.
Also, crazy coincidence, I was just reading one of your posts from 2019 about raycast suspension, and after using your method for the forces it gave me the closest thing to a solution so far, however I can’t get the damping right: it either makes the car oscillate a lot or makes it very unstable.
Here’s what I have right now:
local stiff = tune.springstiffness
local damp = 6*math.sqrt(stiff)
local force = -(ray.Distance-3.55)*stiff-damp*(ray.Distance-suspdata[v.Name])/delta
spring.Force = force*yvector
suspdata[v.Name] = ray.Distance
That was one of the reasons I ultimately gave up on the project. The only way to make it more reliable is to do what Roblox does with physics, and divide your tick function into 4 or more loops. So something like:
Connect(function(_dt)
for _=1, 4 do
local Delta = _dt/4;
-- rest of your code here
end
end)
This will solve the lag spikes. You’ll also need to add a physics throttling multiplier so that your car doesn’t go warp speed when Roblox throttles physics.
I ultimately went to a collision based model and it worked way better. The problem here is how you can’t do anything between Roblox’s 4 physics cycles. So even if your car went through something, raycasting wont tell you what it is. Or some tiny part can end up turning your car into a space shuttle. Not to mention the horror of handling sideways drag.
You’ll have to do it through trial and error. The way I did it was by replacing dampening with a NumberValue inside the script. Then driving around and adjusting it until it felt about right.