function VehicleController.Update(L,M,N,Z)if L.vehicleSeat then if N then M=M+Vector3.new(L.steer,0,L.throttle)if Z and(onlyTriggersForThrottle and useTriggersForThrottle)then L.vehicleSeat.ThrottleFloat=-L.throttle else L.vehicleSeat.ThrottleFloat=-M.Z end L.vehicleSeat.SteerFloat=M.X return M,true else local N=L.vehicleSeat.Occupant.RootPart.CFrame:VectorToObjectSpace(M)L.vehicleSeat.ThrottleFloat=L:ComputeThrottle(N)L.vehicleSeat.SteerFloat=L:ComputeSteer(N)return ZERO_VECTOR3,true end end return M,false end function VehicleController.ComputeThrottle(N,M)if M~=ZERO_VECTOR3 then local N=-M.Z return N else return.0 end end function VehicleController.ComputeSteer(N,M)if M~=ZERO_VECTOR3 then local Z=-math.atan2(-M.x,-M.z)*(180/math.pi)return Z/N.autoPilot.MaxSteeringAngle else return.0 end end function VehicleController.SetupAutoPilot(M)M.autoPilot.MaxSpeed=M.vehicleSeat.MaxSpeed M.autoPilot.MaxSteeringAngle=AUTO_PILOT_DEFAULT_MAX_STEERING_ANGLE end return VehicleController

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
