How would I modify the LookVector to keep the vehicle from flying?

So recently, I had this glitch with the roblox jeep that causes the vehicle to fly into the air, or fly into the ground. The reason why this happens is because when the vehicle is moving forward the vehicle moves forward using velocity it uses lookvector. So if the vehicle is tilting upward, then the vehicle is going to want to go into the air, or if the vehicle is tilting down, then the vehicle is going is to go into the ground (If the vehicle is accelerating forward)

Here is an image of what I mean:

I don’t know how to stop this from happening. Here is an image of what should be happening instead:

How can I keep this from happening? I can’t apply a force to the wheels because the wheels are going to be rotating, plus I would rather apply a force to the main vehicle chassis.

I have no more words to describe the help I need. If someone tell me what I can do to fix this, then no words would describe how happy I feel.

Here is the jeep:

Here are the lines of code that I have changed:

Line 160: local rotVelocity = humanoidRootPart.CFrame:vectorToWorldSpace( * stats.Speed.Value / 12.5, 0, -humanoidRootPart.RotVelocity.Y * 5 * movement.Y)) -- Originally 12.5 was 50, but since this is a modified jeep, it's going to be different.

Line 122: wheelWeld.C0 =, -math.min(thrusterHeight, stats.Height.Value * 2) + (wheelWeld.Part1.Size.Y / 2), 0) -- Originally * 2 was * 0.8, But you know why ;)...

Here is line of code that moves the vehicle: 154, and 155: local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.1)


I think there might be a few opportunities to simplify what’s going on here.

Assuming a variable weight distribution over the front and rear axle we know that accelerating or decelerating at given rate means that the weight on the front and rear axle changes the tilt of the car body. If this is the case, why are you choosing to move the car using the lookvector of the car body?

In an ideal scenario the engine turns the wheels forward, the wheels push backward on the road surface and, in reaction, the road surface pushes back in a forward direction. This means that rather than the velocity being dependent upon the lookvector of the carbody, the speed, or velocity vector is determined by handling the longitudinal and lateral forces separately in conjunction with the magnitude of your Engineforce.

TLDR: The direction of your Engineforce can be determined using the slope between the front and rear axles. This means that the body of your car will no longer determine its heading. The overall directional velocity of your car takes many factors into account; wheel force, braking force, drag etc. This means that if we were to ignore resistance forces like this we would find our car accelerating to infinite speeds; hence your car taking off like a plane.

1 Like

But what else would I use to move the car with? I am not a math expert.

Make a frame for the bottom of the car if you can. The frame of the car is always on the same plane as both axles, whereas the body is placed upon the shocks to provide stabilization. The frame provides you with a rigid body in which you could apply velocity. This could be a transparent part, or a visible one, as long as the axles always remain in the same position in respect to the frame (A constraint or something of the sort).

1 Like

You could average the position of the front and back wheels and take them away from each other to get a vector pointing from the middle of the rear axel to the middle of the front axel:

local lookVector = ( ( wheelFL.CFrame.p + wheelFR.CFrame.p ) - ( wheelRL.CFrame.p + wheelRR.CFrame.p ) ).Unit

YourBodyVelocity.Velocity = lookVector * Your speed
1 Like

Would this need a bodyvelocity? Or can I use regular velocity / a bodyforce bodymover?

Shouldn’t really matter too much. You can directly set the velocity of a central part or put a BodyVelocity inside of that part.

Doing it directly stops you from needing to worry about MaxForce and any resistance, so if the original jeep does it directly then go for that :slight_smile:

So where it says

local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value

I’d replace with

local lookVector = ( ( wheelFL.CFrame.p + wheelFR.CFrame.p ) - ( wheelRL.CFrame.p + wheelRR.CFrame.p ) ).Unit

local velocity = lookVector * stats.Speed.Value

And then the part where it does the setting of the velocity to humanoidRootPart and does the lerp, just keep that as it originally was. So all you’re doing is swapping out the lookVector part really. I don’t know what the movement.Y term is intended to do, but if you have any issues try adding it back in.

And make sure to define the wheels or swap out those variables if you already have the wheels somewhere in the script.

Give it a go and see if that works for you.


Why does this happen:

Here is the jeep:

I was forgetting to apply the velocity to the car. That’s why it was doing that!

How come I can’t reverse though? I can move forward. But even if I press ‘S’ I move forwards instead of backwards. Plus I still fly in the air / do weird things.

Possibly because you are defining the lookVector to always be the forward-facing vector. In that case, you may want to consider negating it under the conditions where the vehicle is supposed to reverse, aka, when S is pressed.

1 Like

Apologies, I made an assumption that your speed value would be negative for going backwards. As @WoolHat suggests, if you’re reversing and your stats.Speed.Value is a positive then you’ll want to negate it.

I think that’s what movement.Y did in the original script, so you can add that same term back in and it should fix it.

1 Like