Hey guys, basically my issue is my chassis seems to be getting caught? Im not sure, the turning is acting weird and im not sure how to fix it. Is my only option making a stricter script-based-chassis? If anybody could help me figure out why its acting weird that would be awesome.
Ive dropped my script below. I did have AI set up the values because I wasnt sure what they should be.
local RunService = game:GetService("RunService")
local car = script.Parent
local driveSeat = car:WaitForChild("DriveSeat")
local leftMotor = car:WaitForChild("LeftMotor")
local rightMotor = car:WaitForChild("RightMotor")
local leftServo = car:WaitForChild("LeftServo")
local rightServo = car:WaitForChild("RightServo")
local MAX_SPEED = 35
local ACCELERATION_RATE = 12
local DECELERATION_RATE = 28
local LEFT_MOTOR_DIRECTION = -1
local RIGHT_MOTOR_DIRECTION = 1
local LOW_SPEED_STEER = 32
local HIGH_SPEED_STEER = 32
local STEERING_SPEED_REFERENCE = 45
local STEER_INPUT_SMOOTHNESS = 9
local MAX_STEER_CHANGE_PER_SECOND = 90
local LEFT_STEER_DIRECTION = 1
local RIGHT_STEER_DIRECTION = 1
local currentMotorSpeed = 0
local targetMotorSpeed = 0
local currentSteerInput = 0
local targetSteerInput = 0
local currentSteerAngle = 0
local function configureMotor(motor)
motor.ActuatorType = Enum.ActuatorType.Motor
motor.MotorMaxTorque = 150000
motor.MotorMaxAcceleration = 80
end
local function configureServo(servo)
servo.ActuatorType = Enum.ActuatorType.Servo
servo.AngularSpeed = 6
servo.AngularResponsiveness = 25
servo.ServoMaxTorque = 250000
end
configureMotor(leftMotor)
configureMotor(rightMotor)
configureServo(leftServo)
configureServo(rightServo)
local function moveToward(currentValue, targetValue, maximumChange)
if currentValue < targetValue then
return math.min(currentValue + maximumChange, targetValue)
elseif currentValue > targetValue then
return math.max(currentValue - maximumChange, targetValue)
end
return currentValue
end
local function updateThrottleInput()
targetMotorSpeed = MAX_SPEED * driveSeat.ThrottleFloat
end
local function updateSteeringInput()
targetSteerInput = driveSeat.SteerFloat
end
driveSeat:GetPropertyChangedSignal("ThrottleFloat"):Connect(updateThrottleInput)
driveSeat:GetPropertyChangedSignal("SteerFloat"):Connect(updateSteeringInput)
RunService.Heartbeat:Connect(function(deltaTime)
local speedChangeRate
if math.abs(targetMotorSpeed) > math.abs(currentMotorSpeed) then
speedChangeRate = ACCELERATION_RATE
else
speedChangeRate = DECELERATION_RATE
end
currentMotorSpeed = moveToward(
currentMotorSpeed,
targetMotorSpeed,
speedChangeRate * deltaTime
)
leftMotor.AngularVelocity = currentMotorSpeed * LEFT_MOTOR_DIRECTION
rightMotor.AngularVelocity = currentMotorSpeed * RIGHT_MOTOR_DIRECTION
local steerAlpha = 1 - math.exp(-STEER_INPUT_SMOOTHNESS * deltaTime)
currentSteerInput += (targetSteerInput - currentSteerInput) * steerAlpha
local vehicleSpeed = driveSeat.AssemblyLinearVelocity.Magnitude
local speedAlpha = math.clamp(vehicleSpeed / STEERING_SPEED_REFERENCE, 0, 1)
local maximumSteerAngle = LOW_SPEED_STEER
+ (HIGH_SPEED_STEER - LOW_SPEED_STEER) * speedAlpha
local desiredSteerAngle = maximumSteerAngle * currentSteerInput
currentSteerAngle = moveToward(
currentSteerAngle,
desiredSteerAngle,
MAX_STEER_CHANGE_PER_SECOND * deltaTime
)
leftServo.TargetAngle = currentSteerAngle * LEFT_STEER_DIRECTION
rightServo.TargetAngle = currentSteerAngle * RIGHT_STEER_DIRECTION
end)
updateThrottleInput()
updateSteeringInput()
Also, sometimes when I turn too hard the wheels randomly lock up. Im not sure what im doing wrong.