My car is acting pretty weird, it does this drift after you hit a certain speed, I didn’t script it to be this way (or unintentionally at least) I think my math on the car is bad. When you are going forward, then turn right and let go it automatically drifts. this is how it looks like:
Pretty bad, this is my code that handles with the car moving and what not;
local attFL = car.Chassis.Platform.AttachmentFL
local attFR = car.Chassis.Platform.AttachmentFR
local attBL = car.Chassis.Platform.AttachmentBL
local attBR = car.Chassis.Platform.AttachmentBR
local CylBL = car.Chassis.Platform.CylindricalBL
local CylBR = car.Chassis.Platform.CylindricalBR
local CylFL = car.Chassis.Platform.CylindricalFL
local CylFR = car.Chassis.Platform.CylindricalFR
local ms = 30
local steer = 0
local throttle = 0
local ms = 30
local function Update(dt)
--Steer;
local goal = -seat.SteerFloat * ms
steer += (goal - steer) * math.min(dt * seat.TurnSpeed, 1)
local radians = math.rad(90 - math.abs(steer))
local h = -(attFR.WorldPosition - attBR.WorldPosition).Magnitude
local z = (attBR.WorldPosition - attBL.WorldPosition).Magnitude
local x = math.tan(radians) * h
local y = (x + z)
local OTA = 90 - math.deg(math.atan2(y, h))
if (steer > 0)then
attFL.Orientation = Vector3.new(0, OTA, 90)
attFR.Orientation = Vector3.new(0, steer, -90)
else
--ri
OTA = -OTA
attFL.Orientation = Vector3.new(0,OTA,90)
attFR.Orientation = Vector3.new(0,steer,-90)
end
--Throttle;--Mathy part,
local ThrottleGoal = seat.ThrottleFloat
throttle += (ThrottleGoal - throttle) * math.min(dt * seat.TurnSpeed, 1)
local Torque = seat.Torque
local speed = seat.MaxSpeed * throttle
CylBL.MotorMaxTorque = Torque
CylBR.MotorMaxTorque = Torque
CylBL.AngularVelocity = speed
CylBR.AngularVelocity = -speed
end
The throttle part is very simple but idk why its like that. I don’t know if its the carSeat as well or my script. When you let go if should stop not continue turning or not, So i think this might be the carSeat behaving weird. But when I was driving I was observing the throttle values in VehicleSeat , when I let go all the values stop, but the car keeps going, as in it turns even though the player didn’t make it turn. So do i have to add a script were it sets the speed to zero when all those values stop? Again, I don’t want it to do that turn even though the player didn’t want it to turn, if you want more info on the car please reply and say so.