How to fix drifting problem

Hi,

So I’ve been trying to understand the default jeep and I ran into this problem. The jeep begins to “drift” when I turn. This is because I changed value in the LocalCarScript which is “0.01” which makes it accelerates it slower and it starts to drift once this value has been changed.

humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.01)

What happens


What I want to happen

This is the LocalCarScript

while game:GetService("RunService").Heartbeat:wait() and car:FindFirstChild("DriveSeat") and character.Humanoid.SeatPart == car.DriveSeat do
		--game:GetService("RunService").RenderStepped:wait()
		if IsGrounded() then
			if movement.Y ~= 0 then
				local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value
				humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.01)
				bodyVelocity.maxForce = Vector3.new(0, 0, 0)
			else
				bodyVelocity.maxForce = Vector3.new(mass / 2, mass / 4, mass / 2)
			end
			local rotVelocity = humanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -humanoidRootPart.RotVelocity.Y * 5 * movement.Y))
			local speed = -humanoidRootPart.CFrame:vectorToObjectSpace(humanoidRootPart.Velocity).unit.Z
			rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y)
			if math.abs(speed) > 0.1 then
				rotVelocity = rotVelocity + humanoidRootPart.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0)))
				bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
			else
				bodyAngularVelocity.maxTorque = Vector3.new(mass / 4, mass / 2, mass / 4)
			end
			humanoidRootPart.RotVelocity = humanoidRootPart.RotVelocity:Lerp(rotVelocity, 0.1)
			
			--bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3)
			--bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6)
		else
			bodyVelocity.maxForce = Vector3.new(0, 0, 0)
			bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
		end
		
		for i, part in pairs(car:GetChildren()) do
			if part.Name == "Thruster" then
				UpdateThruster(part)
			end
		end
	end
	for i, v in pairs(car:GetChildren()) do
		if v:FindFirstChild("BodyThrust") then
			v.BodyThrust:Destroy()
		end
	end
	bodyVelocity:Destroy()
	bodyAngularVelocity:Destroy()
	--camera.CameraType = oldCameraType
	script:Destroy()
--end)

Anybody with answers is greatly appreciated thank you.If I don’t respond I’m on online and I’m sleeping

I think it has to do with the fact that that script moves the vehicle by the BodyForces applied to the Humanoid. I’m just guessing but you may need to change this line too to change the rotation of the force:

1 Like

thanks for responding. I tested this out and and so I changed it to 0.01 and it just makes it so I turn very slower.

It’s a balancing act, since you are changing all the values of the forces applied on the Humanoid, rather than just steering the vehicle with one line of script and accelerating with another line.
There’s probably another line in the script which may be affecting the drift. I’m not really a scripter so I don’t understand everything that’s going on.

1 Like

The main problem with this is that once I start going straight then I turn, the velocity keeps going and it drifts before changing the velocity to the lookvector and I have no idea how to fix it. In the jailbreak example, when I turn it immediately starts turning the direction of the front of the car. However, with the current jeep, the velocity keeps going for some time before going the direction of where the player is facing

I don’t understand anything about scripting cars, but you have to make the front turn faster than the back.

Because you are lerping humanoidRootPart’s velocity to the target velocity, you are actually dampening the acceleration. A good way to think about this is that the reaction time of the car to your inputs is being slowed, but the target velocity that the car wants to go is still as fast as before.

I assume what you want is a faster reaction time, but still a slower top speed. You will want to multiply the velocity variable with a number < 1 so that your target velocity is a lower speed, and raise the 0.01 value to a higher number so that your car can react to this faster. This might help mitigate the drifting issue

2 Likes