Your car is going backwards so fast because the base force (Throttle * Power
) is negative and the drag (Drag * Speed
) is also negative. This means that when you go backwards, your “drag” force gets higher and increases in acceleration the faster you go. It’s supposed to decelerate you, not accelerate you.
When the car goes forwards, it reaches a speed limit because the base force (Throttle * Power
) is positive while the drag (Drag * Speed
) is negative. You reach top speed when the two are approximately opposites and add up to 0.
Obviously, if both are negative then they will never add to equal 0. The speed will just increase constantly since the car gets a higher and higher acceleration (force).
@madattak tried to fix this by getting the relative velocity of the car instead of the speed. Speed is directionless – it must be a positive number indicating how fast you are going in any direction. Velocity on the other hand indicates a direction, which is exactly what we need!
What we need is for the drag to be positive – instead of negative – if the car is moving backwards. If we use the X Velocity instead of the Speed, we can get a “negative speed” since velocity includes direction.
This is what @madattak tried to do, but he didn’t get just the X velocity, he tried to use the whole Vector X, Y, and Z velocities at once. This caused an error. I figure this was a typo.
Additionally, multiplying Dir by “Speed” would cause the negatives to cancel out and we’d end up back at step 1.
Here is an amended example script that should work:
AxisVelocity = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).X
vf.Force = Vector3.new(Throttle * Power - Drag * AxisVelocity,0,0)
I tested this out with a power of 10000 and a drag of 100 and was able to reach a top speed of 62 both forwards and backwards.