function Engine.Update(B)local n=B.Main.CFrame local x=B.Main.Velocity local c=n.lookVector local g=n.upVector local X=n.rightVector local Q=math.abs(x:Dot(c))local z=B.PitchInput local y=B.YawInput local w=1 local f=EngineRate(w+minThrottle*(1-w))B.speed=B.Main.Velocity.magnitude if B.BoostInput==-1 then return end MotorSound.Volume=f^.33333333333333*.4 MotorSound.PlaybackSpeed=f pitchFx.Octave=1/(f<.0001 and.0001 or f)local m=B.BoostInput==1 and B._BOOSTSPEED or B.BoostInput==0 and B._SPEED or 0 B.Thruster.Velocity=(n.lookVector*(m*f))*v3(1,.8,1)B.Steering.CFrame=cf(v3null,n.lookVector)*(EulerXYZ(0,y*B._YAW,0)*EulerXYZ(B._PITCH*z,0,y*B._ROLL))B.Steering.MaxTorque=v3(25,25*abs(g.y),25)*(Q/m)^2 B.Steering.P=3000*Clamp((Q/m)^2/2+.5,0,1)B.Thruster.MaxForce=v3(100000,math.huge,100000)end

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()