Just making a car that uses motors and servos to drive be able to steer with A and D alone.
If someone would like to provide a helpful guide feel free to do so.
I’m hoping I don’t need to provide too much context pertaining to the code.
-- get the specifications
local speed = script.speed.Value
local accleration = script.acceleration.Value
local steeringspeed = script.steeringSpeed.Value
local steeringangle = script.steeringAngle.Value
-- set up the shortcuts
local vehicle = script.Parent.Parent
local seat = script.Parent
-- find the tires
local A = vehicle.A -- front left
local AA = vehicle.AA -- front right
local B = vehicle.B -- back left
local BB = vehicle.BB -- back right
-- find the steering mechanism
local steerA = vehicle.SteeringA.Servo
local steerB = vehicle.SteeringB.Servo
-- set up wheels' motor accerlation
A.Motor.MotorMaxTorque = accleration
AA.Motor.MotorMaxTorque = accleration
B.Motor.MotorMaxTorque = accleration
BB.Motor.MotorMaxTorque = accleration
while true do
-- power the wheels
local velocity = seat.Throttle * speed -- use the seat's throttle to determine the wheels' action (backward? forward? nothing?)
local steer = seat.Steer
if steer == '1' then
A.Motor.AngularVelocity = -velocity
AA.Motor.AngularVelocity = -velocity
B.Motor.AngularVelocity = -velocity
BB.Motor.AngularVelocity = -velocity
elseif steer == '-1' then
A.Motor.AngularVelocity = velocity
AA.Motor.AngularVelocity = velocity
B.Motor.AngularVelocity = velocity
BB.Motor.AngularVelocity = velocity
else
A.Motor.AngularVelocity = velocity
AA.Motor.AngularVelocity = velocity
B.Motor.AngularVelocity = -velocity
BB.Motor.AngularVelocity = -velocity
end
wait()
-- steering
local steering = seat.Throttle * speed
steerA.AngularSpeed = steeringspeed
steerA.ServoMaxTorque = 100000000
steerA.TargetAngle = steeringangle*seat.Steer
steerB.AngularSpeed = steeringspeed
steerB.ServoMaxTorque = 100000000
steerB.TargetAngle = steeringangle*seat.Steer
end
I have already made this much of an attempt and I’m ready to call it a night.