I am trying to make a snippet of code which will de-accelerate a car if there’s no DriveSeat.Throttle
However, The following way to determine direction, returns 0 always.
Direction = math.floor(Chassis.Throttle.Velocity.Unit:Dot(Chassis.CFrame.LookVector))
It does not de-accelerate the car at all, Here’s the rest of my code:
--[[ After that, Throttle and Steer | Made by InternallyAmplified ]]--
local MaxSpeed = Car.Config.MaxSpeed.Value
--Update Alpha if it's zero
if DriveSeat.Throttle == 0 and Chassis.Throttle.Velocity.Magnitude ~= 0 then
Direction = math.floor(Chassis.Throttle.Velocity.Unit:Dot(Chassis.CFrame.LookVector))
Alpha = math.clamp(Alpha - (step * Direction),-5,5)
if Alpha ~= 0 then
if -0.05 < Alpha and Alpha < 0.05 then
Alpha = 0
end
end
else
Alpha = math.clamp(Alpha + (step * Direction),-5,5)
end
local y = (math.atan(Alpha) * 3.5) / 5
local Vel = math.clamp(y * MaxSpeed, -Car.Config.MinimumSpeed.Value, MaxSpeed)
Chassis.Throttle.Velocity = Chassis.CFrame.LookVector * -Vel * Vector3.new(1,0,1)