function VehicleController.Update(W,s,Z,e)if W.vehicleSeat then if Z then s=s+Vector3.new(W.steer,0,W.throttle)if e and(onlyTriggersForThrottle and useTriggersForThrottle)then W.vehicleSeat.ThrottleFloat=-W.throttle else W.vehicleSeat.ThrottleFloat=-s.Z end W.vehicleSeat.SteerFloat=s.X return s,true else local Z=W.vehicleSeat.Occupant.RootPart.CFrame:VectorToObjectSpace(s)W.vehicleSeat.ThrottleFloat=W:ComputeThrottle(Z)W.vehicleSeat.SteerFloat=W:ComputeSteer(Z)return ZERO_VECTOR3,true end end return s,false end function VehicleController.ComputeThrottle(Z,s)if s~=ZERO_VECTOR3 then local Z=-s.Z return Z else return.0 end end function VehicleController.ComputeSteer(Z,s)if s~=ZERO_VECTOR3 then local e=-math.atan2(-s.x,-s.z)*(180/math.pi)return e/Z.autoPilot.MaxSteeringAngle else return.0 end end function VehicleController.SetupAutoPilot(s)s.autoPilot.MaxSpeed=s.vehicleSeat.MaxSpeed s.autoPilot.MaxSteeringAngle=AUTO_PILOT_DEFAULT_MAX_STEERING_ANGLE end return VehicleController
-- Call this from a function bound to Renderstep with Input Priority
function VehicleController:Update(moveVector, cameraRelative, usingGamepad)
	if self.vehicleSeat then
		if cameraRelative then
			-- This is the default steering mode
			moveVector = moveVector + Vector3.new(self.steer, 0, self.throttle)
			if usingGamepad and onlyTriggersForThrottle and useTriggersForThrottle then
				self.vehicleSeat.ThrottleFloat = -self.throttle
			else
				self.vehicleSeat.ThrottleFloat = -moveVector.Z
			end
			self.vehicleSeat.SteerFloat = moveVector.X

			return moveVector, true
		else
			-- This is the path following mode
			local localMoveVector = self.vehicleSeat.Occupant.RootPart.CFrame:VectorToObjectSpace(moveVector)

			self.vehicleSeat.ThrottleFloat = self:ComputeThrottle(localMoveVector)
			self.vehicleSeat.SteerFloat = self:ComputeSteer(localMoveVector)

			return ZERO_VECTOR3, true
		end
	end
	return moveVector, false
end

function VehicleController:ComputeThrottle(localMoveVector)
	if localMoveVector ~= ZERO_VECTOR3 then
		local throttle = -localMoveVector.Z
		return throttle
	else
		return 0.0
	end
end

function VehicleController:ComputeSteer(localMoveVector)
	if localMoveVector ~= ZERO_VECTOR3 then
		local steerAngle = -math.atan2(-localMoveVector.x, -localMoveVector.z) * (180 / math.pi)
		return steerAngle / self.autoPilot.MaxSteeringAngle
	else
		return 0.0
	end
end

function VehicleController:SetupAutoPilot()
	-- Setup default
	self.autoPilot.MaxSpeed = self.vehicleSeat.MaxSpeed
	self.autoPilot.MaxSteeringAngle = AUTO_PILOT_DEFAULT_MAX_STEERING_ANGLE

	-- VehicleSeat should have a MaxSteeringAngle as well.
	-- Or we could look for a child "AutoPilotConfigModule" to find these values
	-- Or allow developer to set them through the API as like the CLickToMove customization API
end

return VehicleController
