Make car stop when hit wall

So I have this Speeder I am making, it works fine except when it gets to an object which is too steep or like a wall it will just tilt its back and slam against it.

I am using a combination of BodyVelocity, BodyAngularVelocity and BodyGyros for this but I am unsure how to prevent this problem.

Example: https://gyazo.com/fa3bc869ff509e18d642282ad9e08f06

2 Likes
local a = hit.Parent:findFirstChild("VehicleSeat")
if a ~= nil then
a.MaxSpeed = 0
a.TurnSpeed = 0
end
end

script.Parent.Touched:connect(onTouched)

I didn’t test it, but if it doen’t works, try the second option, duplicate the block, make cancollide false and move it 1 stud before the car hit the wall.

EDIT: I forgot to say that change vehicle seat to the front part of the car, if it touchs it and find the vehicle seat in the car then the scripts do it’s function :slight_smile:

The issue with a simple .Touched script is what if it hits an object that it is meant to go up? e.g. a ramp

Maybe the vehicle mesh? or the wall is very thin? or the speed

Same as what Conejin_Alt suggested.
I tried this and it kinda worked but it was very inaccurate and not the solution I’m looking for.

Just get a script to set your vehicles body velocity thrust to 0 when it the front touches an object

no , the op wants so it stops if it collides, only with a part, if its a ramp then nothing should happen…
It’s worth noting that my provided script works , but for some reason he didnt mark it as a solution despite acknowledging that it does

The issue with the .Touched is simply that it isn’t accurate. If for example you bumped into another speeder or the detector part nicked the side of a block, it would stop the speeder completely.

I am not after a solution that is inaccurate, please re-read what I have said.
And by a ramp I mean a surface that is rotated or like slanted e.g. Terrain.

There is also no such thing as a “Ramp” as an object in roblox… please check your answers.

Already addressed this a few times now.

Thanks for trying but…

As I have already stated.
This will not work for terrain, yes you can detect if you touch terrain, but you can’t simply know if it was flat or a wall or slightly slanted.
There is little point in me marking every object, that would take a very long time for me to go through and check by myself if an object should be able to stop a speeder or not.

Even if all these conditions did work, .Touched still behaves too weirdly for this to be a good idea.

Touched isn’t good for these things at all. To many edge cases and bugs at high speeds.

For the problem in the GIF of your original post, a strong BodyGyro on the X axis should prevent this from happening. However that would also completely prevent it from going up ramps without a script.

One solution could be to calculate the current translational force your forces are exerting on the model and compare it to the actual acceleration/velocity of any part. If the forces are significantly more than how fast it’s moving, adjust the forces to be less, until all translational forces are zero when the model doesn’t move on the horizontal axis.

Or, to prevent high velocity impacts, you can periodically check how much the velocity changes over time. If the object slows down significantly more in a frame/split second than it can brake, disable the forces for a short time.

How would I go about calculating this?

What forces are you currently using? How strong are they/can they be?

You can actually have a welded part onto the front of the car(a one that isn’t touching the ground), and put the script inside the part

I’m not really sure how to go about answering this?
I am simply using a BodyVelocity to move the Speeder if that helps.

For anyone that is still having a problem like this, try changing your BodyVelocity.MaxForce from math.huge to 99999