-- Update engine forces base on control input

function Engine:Update()	
	local c = self.Main.CFrame
	local vel = self.Main.Velocity
	
	local bz = c.lookVector
	local by = c.upVector
	local bx = c.rightVector
	local speed = math.abs(vel:Dot(bz))
	
	local stick_pitch = self.PitchInput
	local stick_yaw = self.YawInput

	local throttle = 1
	local rev = EngineRate(throttle + minThrottle*(1 - throttle))
	
	self.speed = self.Main.Velocity.magnitude
	
	if self.BoostInput == -1 then
		return
	end
	
	MotorSound.Volume = rev^(1/3)*0.4
	MotorSound.PlaybackSpeed = rev
	pitchFx.Octave = 1/(rev < 1e-4 and 1e-4 or rev)
	
	local targetSpeed = ((self.BoostInput == 1 and self._BOOSTSPEED) or (self.BoostInput == 0 and self._SPEED) or 0)
	self.Thruster.Velocity = c.lookVector*(targetSpeed*rev)*v3(1, 0.8, 1)
	self.Steering.CFrame = cf(v3null, c.lookVector)*(EulerXYZ(0, stick_yaw*self._YAW, 0)*EulerXYZ(self._PITCH*stick_pitch, 0, stick_yaw*self._ROLL))
	self.Steering.MaxTorque = v3(25, 25*abs(by.y), 25)*(speed/targetSpeed)^2
	self.Steering.P = 3000*Clamp((speed/targetSpeed)^2/2 + 0.5, 0, 1)
	self.Thruster.MaxForce = v3(100000, math.huge, 100000)
end -- Engine:Update()