Simple car is sliding

Hi, I tried to make a simple car, but it’s sliding movement. I want it to be like a car.

There’s linear velocity and angular velocity being used. Below is the code:

local seat = script.Parent.VehicleSeat
local occupied = false
local force1 = script.Parent.base.LinearVelocity
local turn = script.Parent.base.AngularVelocity
--[[seat.Occupant.Changed:Connect(function()
	print("reached")
	if(occupied == false) then

		occupied = true
	else
		occupied = false
		force1.Enabled=false	
	end

end)]]
local currkey = nil
seat:GetPropertyChangedSignal("Throttle"):Connect(function()
	print("reached")
	if seat.Throttle==1 then
		force1.LineVelocity=4000
		force1.Enabled=true
	
	elseif seat.Throttle==-1 then
		force1.LineVelocity=-4000
		force1.Enabled=true
		 
		force1.Enabled=false
	end
end)
seat:GetPropertyChangedSignal("Steer"):Connect(function()
	
	if seat.Steer==1 then
		turn.AngularVelocity=Vector3.new(3, 0, 0)
		turn.Enabled=true

	elseif seat.Steer==-1 then
		turn.AngularVelocity=Vector3.new(-3, 0, 0)
		turn.Enabled=true

	else
		turn.Enabled=false
	end
end)

Can someone help me? I don’t want it to slide when it moves. It turns in the right direction but keeps sliding.
Perhaps it’s something to do with my turning? I’m not sure…

Sincerely
-coolguyweir

1 Like

Perhaps decrease density of parts, maybe that’ll solve your problem.

Problem:
It seems like you are using LinearVelocity with VelocityConstraintMode property set to Line
The line mode will only apply force in the direction of the line, and will not apply any force that’s not in the direction of the line
For example, if the line is facing forward then it won’t apply any force to prevent sliding right and left and it will also not apply any force to stop it from going up and down
Solution:
To prevent the car from sliding right and left you can add another Attachment and LinearVelocity with VelocityConstraintMode property set to Line, RelativeTo property set to Attachment0 and with the line facing right, also set the Attachment0 to the attachment you just created, not the one you used for forward and backward force
To make the LinearVelocity face right just rotate the attachment

So should I remove angular velocity and do that instead?

No, keep the angular velocity for the car to be able to turn, since the angular velocity has nothing to do with the car sliding right and left

Where should I position the new linear velocity?

The same place where u positioned the old linear velocity but rotate it 90 degrees on the y axis

if I were to rotate car wheels instead of the whole car body, do you think it’ll still slide?

Don’t rotate the wheels or the car body, rotate the attachment

Maybe try increasing the friction of all parts touching the ground when braking/nobody is in the driver’s seat.