From 1f7e97d7db5254a3981161c295da8a744cbb4c9a Mon Sep 17 00:00:00 2001 From: Redox Date: Sat, 28 Dec 2024 16:07:40 +0100 Subject: [PATCH] Add rotorwash logic --- lua/entities/base_glide_heli/init.lua | 25 +++++++++++++++++++++++++ lua/entities/glide_rotor.lua | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/lua/entities/base_glide_heli/init.lua b/lua/entities/base_glide_heli/init.lua index a74bd95..d6c510e 100644 --- a/lua/entities/base_glide_heli/init.lua +++ b/lua/entities/base_glide_heli/init.lua @@ -110,6 +110,31 @@ function ENT:OnDriverExit() end end +-- Create a rotorwash entity +function ENT:CreateRotorWash() + if IsValid( self.rotorWash ) then + return self.rotorWash + end + + local rotorWash = ents.Create( "env_rotorwash_emitter" ) + self.rotorWash = rotorWash + rotorWash:SetPos( self:WorldSpaceCenter() ) + rotorWash:SetParent( self ) + rotorWash:Spawn() + + self:DeleteOnRemove( rotorWash ) + + return rotorWash +end + +-- Remove the rotorwash entity +function ENT:RemoveRotorWash() + if IsValid( self.rotorWash ) then + self.rotorWash:Remove() + self.rotorWash = nil + end +end + local IsValid = IsValid local Approach = math.Approach local ExpDecay = Glide.ExpDecay diff --git a/lua/entities/glide_rotor.lua b/lua/entities/glide_rotor.lua index 16745b4..e91deb1 100644 --- a/lua/entities/glide_rotor.lua +++ b/lua/entities/glide_rotor.lua @@ -137,6 +137,11 @@ function ENT:Think() if self.isSpinningFast ~= isSpinningFast then self.isSpinningFast = isSpinningFast self:SetModel( isSpinningFast and self.modelFast or self.modelSlow ) + if isSpinningFast then + self:GetParent():CreateRotorWash() + else + self:GetParent():RemoveRotorWash() + end end local dt = FrameTime()