# Linear velocity car is wrongfully sliding?

Hi,

I recently made a small car template.

There’s a linear velocity pointing forwards in front of the car that makes the car go forwards and backwards.

However, how would I make the car turn properly without sliding while turning? The car seems to only turn correctly when at very low speeds, and at higher speeds it just slides and turns slowly like on ice or something.

Thanks
-coolguyweir

1 Like
1. Create a car model: First, create a car model with two wheels at the front and two wheels at the back.

2. Apply a motor to the rear wheels: Apply a motor to the rear wheels of the car to make it move forward and backward. You can do this by adding a Motor6D constraint to each rear wheel.

3. Add a script: Add a script to the car to handle steering. The script should listen for user input (e.g., arrow keys) to turn the front wheels of the car. You can use the BodyAngularVelocity property of the front wheels to rotate them in the desired direction.

Here’s an example code snippet to get you started with the steering script:

``````-- Get the front wheels of the car
local frontLeftWheel = script.Parent.FrontLeftWheel
local frontRightWheel = script.Parent.FrontRightWheel

-- Set the maximum turn speed of the wheels
local maxTurnSpeed = 2 -- radians per second

-- Listen for user input
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Left then
-- Turn left
frontLeftWheel.BodyAngularVelocity = Vector3.new(0, -maxTurnSpeed, 0)
frontRightWheel.BodyAngularVelocity = Vector3.new(0, maxTurnSpeed, 0)
elseif input.KeyCode == Enum.KeyCode.Right then
-- Turn right
frontLeftWheel.BodyAngularVelocity = Vector3.new(0, maxTurnSpeed, 0)
frontRightWheel.BodyAngularVelocity = Vector3.new(0, -maxTurnSpeed, 0)
end
end)

-- Stop turning when the user releases the key
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Left or input.KeyCode == Enum.KeyCode.Right then
frontLeftWheel.BodyAngularVelocity = Vector3.new(0, 0, 0)
frontRightWheel.BodyAngularVelocity = Vector3.new(0, 0, 0)
end
end)

``````

Note that this is just a basic example to get you started. You may need to adjust the code and parameters to get the desired behavior for your game.

If I were to use linear velocity and angular velocity, where would I position the two constraints so it doesnt slide across ice?

To make a car turn properly without sliding while turning using linear velocity and angular velocity, you can position the constraints as follows:

1. For the rear wheels: Apply a Motor6D constraint to each rear wheel and set the motor speed based on the user input. This will give the car linear velocity and make it move forward or backward.
2. For the front wheels: Apply a BallSocketConstraint or HingeConstraint to each front wheel, connecting it to the car’s chassis. Then, set the wheel’s angular velocity based on the user input. This will make the front wheels turn left or right, and the car will turn accordingly.

To prevent the car from sliding across the ground, you can adjust the physics properties of the car’s wheels and the ground.

Here’s an example code snippet:

``````-- Get the car model
local car = script.Parent

-- Set the maximum turn speed of the wheels
local maxTurnSpeed = 5 -- radians per second

-- Listen for user input
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Left then
-- Turn left
car.FrontLeftWheel.AngularVelocity = Vector3.new(0, -maxTurnSpeed, 0)
car.FrontRightWheel.AngularVelocity = Vector3.new(0, maxTurnSpeed, 0)
elseif input.KeyCode == Enum.KeyCode.Right then
-- Turn right
car.FrontLeftWheel.AngularVelocity = Vector3.new(0, maxTurnSpeed, 0)
car.FrontRightWheel.AngularVelocity = Vector3.new(0, -maxTurnSpeed, 0)
end
end)

-- Stop turning when the user releases the key
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Left or input.KeyCode == Enum.KeyCode.Right then
car.FrontLeftWheel.AngularVelocity = Vector3.new(0, 0, 0)
car.FrontRightWheel.AngularVelocity = Vector3.new(0, 0, 0)
end
end)

``````