-- ================================================================================
-- PUBLIC FUNCTIONS
-- ================================================================================

function Engine.new(speeder)	
	local newEngine = {}
	setmetatable(newEngine, Engine)

	newEngine.Speeder = speeder
	newEngine.Main = speeder.main
	newEngine.Mass = speeder.mass
	
	-- Attachment
	local attachment = Instance.new("Attachment")
	attachment.Parent = speeder.main
	
	-- Thruster (foward/backward)
	newEngine.Thruster = Instance.new("BodyVelocity")
	newEngine.Thruster.Name = "Thruster"
	newEngine.Thruster.Parent = speeder.main
	
	-- Gyro (steering)
	newEngine.Steering = Instance.new("BodyGyro")
	newEngine.Steering.Name = "Steering"
	newEngine.Steering.Parent = speeder.main
	
	newEngine._settings = speeder._settings
	
	-- Set settings
	newEngine._SPEED = newEngine._settings.DefaultSpeed
	newEngine._BOOSTSPEED = newEngine._settings.BoostSpeed
	newEngine._PITCH = (3.5*newEngine._settings.Steering)*(math.pi/180)
	newEngine._YAW = (-4*newEngine._settings.Steering)*(math.pi/180)
	newEngine._ROLL = (2*newEngine._settings.Steering)*(math.pi/180)
	
	EngineRate = IIRFilter(0.005)
	
	StartSound:Play()
	local soundConnection
	soundConnection = StartSound.Ended:Connect(function()
		MotorSound:Play()
		soundConnection:Disconnect()
	end)
	
	return newEngine
end -- Engine:new()
