Raycast suspension car does not keep up with inclines

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.

Any help is appreciated.

1 Like

Have you tried offsetting the car’s position relative to the raycast distance? It might also be the frequency if raycasts isn’t high enough.

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 think offsetting the position “manually” with code should work fine with physics?

So you mean I would just change the Position of the car manually? Wouldn’t that interfere with the other forces like driving etc.?

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.

I’ll try it out whenever I’m available and I’ll see if it helps.

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

Honestly at this point I’m willing to pay anyone who can help me solve this problem

You’ll want to move the model directly using PivotTo() or SetPrimaryPartCFrame().

1 Like

I don’t want to do that, AlignPosition gives basically the same result anyway.

AlignPosition is your problem here, but this behavior might be good for you actually. You just accidentally made car suspension.

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
1 Like

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.

So are you saying I can’t get the damping right?

Here is what mine looks like right now btw (damp = 6*math.sqrt(stiff), stiffness is 70000, vehicle mass is around 256)

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.

For me it always has this exaggerated bouncy effect no matter what I set it to. Any advice on that?