Need help with a car

Recently i’ve made a simple car that’s using LinearVelocity to move, and it just shuffles on the ground using invisible parts. So when I brake it it just instantly stops moving, what do I need to achieve is to figure a script that’s decreasing linear velocity by 1 while .2 seconds when I stop accelerating. I tried many ways but I couldn’t figure it. Thank you for help!

Here’s an original script:

local seat = script.Parent.DriverSeat.VehicleSeat
local backLeft = script.Parent.BackLeft
local backRight = script.Parent.BackRight
local frontLeft = script.Parent.FrontLeft
local frontRight = script.Parent.FrontRight
local velocity = script.Parent.FrontBack
local rotate = script.Parent.Rotate

local steerAngle = 30
local speed = script.Parent.SpeedValue.Value
local loopvalue = speed
local EngineOn = script.EngineOn

seat:GetPropertyChangedSignal("Steer"):Connect(function()
	frontLeft.PartB.SteeringConstraint.TargetAngle = steerAngle*seat.Steer
	frontRight.PartB.SteeringConstraint.TargetAngle = steerAngle*seat.Steer
	if seat.Steer == 1 then
		frontLeft.PartB.SteeringConstraint.LowerAngle = 30
		frontLeft.PartB.SteeringConstraint.UpperAngle = 0
		frontRight.PartB.SteeringConstraint.LowerAngle = 30
		frontRight.PartB.SteeringConstraint.UpperAngle = 0
		if seat.Velocity.Magnitude > 0 then
			rotate.AngularVelocity = Vector3.new(0, -1, 0)
		end
	elseif seat.Steer == -1 then
		frontLeft.PartB.SteeringConstraint.LowerAngle = -30
		frontLeft.PartB.SteeringConstraint.UpperAngle = 0
		frontRight.PartB.SteeringConstraint.LowerAngle = -30
		frontRight.PartB.SteeringConstraint.UpperAngle = 0
		if seat.Velocity.Magnitude > 0 then
			rotate.AngularVelocity = Vector3.new(0, 1, 0)
		end
	else
		frontLeft.PartB.SteeringConstraint.LowerAngle = 0
		frontLeft.PartB.SteeringConstraint.UpperAngle = 0
		frontRight.PartB.SteeringConstraint.LowerAngle = 0
		frontRight.PartB.SteeringConstraint.UpperAngle = 0
		rotate.AngularVelocity = Vector3.new(0, 0, 0)
	end
end)

-- This is the throttle part

seat:GetPropertyChangedSignal("Throttle"):Connect(function()
	if EngineOn.Value == true then
		frontLeft.Wheel.WheelConstraint.AngularVelocity = speed*seat.Throttle
		frontRight.Wheel.WheelConstraint.AngularVelocity = -speed*seat.Throttle
		backLeft.Wheel.WheelConstraint.AngularVelocity = speed*seat.Throttle
		backRight.Wheel.WheelConstraint.AngularVelocity = -speed*seat.Throttle
		velocity.LineVelocity = speed*seat.Throttle
	end
end)
6 Likes

Why not use a VectorForce instead? From what I’ve seen LinearVelocity (not LineVelocity like you have here: velocity.LineVelocity = speed*seat.Throttle) stops instantly.
You can have something like:

if EngineOn.Value == true then
    -- the code you have
 else
    for decel = (the force you have when driving), 0, (the negative step you want) do
        -- make the LinearVelocity or VectorForce the value of decel
    end
end
5 Likes

I think it stop instantly because invisible parts friction is too high. I’ve tried just disabling it but that didn’t work.

3 Likes

Do you have any other ideas how to make a smooth acceleration and gravity braking?

3 Likes

I’d just use Motor HingeConstraints in the wheels and use a similar script to decrease the values of those.

Are the vehicles sitting on the path parts on the ground? If so make the path parts slightly lower so the cars don’t sit right on them.

3 Likes

Before, I used HingeConstraints, but they got very wobbly and the car just didn’t work well, so I started using a LinearVelocity. The vehicle just has a invisible wheels that don’t move, so it can shuffle on the ground. I did this because I don’t really know how to ray cast.

3 Likes

I just need to figure out how to decrease the LinearVelocity while not accelerating, and how to increase LinearVelocity while accelerating, and these loops could be broken by e.g. accelerating again.

3 Likes

Look up train or cart or roller coaster movement on the forums. Basically that’s what you are trying to create. Instead of using gravity to keep the car down you need a rail to stabilize the car and keep it on track.
I’ve posted a couple of my train models on a few train threads How to make a basic train - #12 by Scottifly and one with dual axle bogeys that tilt and rotate (more than what you need, but still fun) How to make a train bounce up and down? - #2 by Scottifly

2 Likes

I tried to use the Vector Force, and it seems to work well, But I don’t think i can set a max speed of it.

1 Like

Alright, I added wheels and also some springs. Thank you for help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.