Page 1 of 2

Deflector Shields

PostPosted: 02 Feb 2014, 20:47
by Resin_Smoker
Image

Please note that I can do square collision boxes as well.
Currently this shield acts as a deflector, bouncing back any projectiles intersecting it. Of coarse this only protects the front of the unit but it's possible to add as many desired with most any form of mesh needed for the application.

DeflectorShield.lua Code: http://pastebin.com/F6wzhH2Z
Unit script: http://pastebin.com/HSh48Agj
Unit Blueprint: http://pastebin.com/x5F4cYhd
Deflector Mesh Blueprint: http://pastebin.com/t8Hg89uV

please be aware that this is a work in progress but it is functional. Just need optimization and tweeking for effects.

Resin

Re: Deflector Shields

PostPosted: 03 Feb 2014, 08:08
by Golol
lets put it on asf. it sure is going to help the performance :P.

Re: Deflector Shields

PostPosted: 03 Feb 2014, 14:46
by Krapougnak
After Domino, you.
Welcome back Resin you were sorely missed ! 8-)

Re: Deflector Shields

PostPosted: 03 Feb 2014, 15:03
by lextoc
Very nice, you can send them in huge armies hehe

Re: Deflector Shields

PostPosted: 03 Feb 2014, 15:45
by Seriph
Make the projectiles reflect in "random" pattern so you can't have a deflector kill a fatboy by bouncing his projectiles back at him.

Re: Deflector Shields

PostPosted: 03 Feb 2014, 23:25
by Resin_Smoker
Krapougnak wrote:After Domino, you.
Welcome back Resin you were sorely missed ! 8-)


Thank you!

Re: Deflector Shields

PostPosted: 03 Feb 2014, 23:26
by Resin_Smoker
lextoc wrote:Very nice, you can send them in huge armies hehe


They will not be cheap to build and can be flanked as they are not very fast.

Resin

Re: Deflector Shields

PostPosted: 03 Feb 2014, 23:27
by Resin_Smoker
Seriph wrote:Make the projectiles reflect in "random" pattern so you can't have a deflector kill a fatboy by bouncing his projectiles back at him.



Working on this... Currently only effective 10% of the time.

Resin

Re: Deflector Shields

PostPosted: 12 Feb 2014, 15:36
by Resin_Smoker
I've a functional script now!

Re: Deflector Shields

PostPosted: 14 May 2014, 08:21
by Resin_Smoker
This is what it looks like when projectiles can be reflected.... https://www.youtube.com/watch?v=AFMtjSJ ... e=youtu.be

Please keep in mind that this was done just to test the concept. Below is a copy of the script used via Projectile.lua hook.

Code: Select all
do

local Util = import('/lua/utilities.lua')
local Entity = import('/lua/sim/Entity.lua').Entity
local oldProjectile = Projectile
local EffectTemplate = import('/lua/EffectTemplates.lua')
local utilities = import('/lua/utilities.lua')

--> Triggers all logs to report if flag set true, selfwise use the local flags within each function for specific outputs
local masterDebug = false

Projectile = Class(oldProjectile) {

   OnImpact = function( self, targetType, targetEntity )      
      local myDebug = true
      if masterDebug and myDebug then
         WARN('OnImpact')
         WARN('   projectile "self" ID:', self:GetEntityId() )
         if targetEntity != nil then
            WARN('   targetEntity ID:', targetEntity:GetEntityId() )
         else
            WARN('   no target, assuming projectile impacted ground')         
         end         
      end
      --> Prevent projectiles used in as props or effects from triggering reflection
      if self and not self:BeenDestroyed() and targetEntity != nil then   
         if self.DamageData and self.DamageData.DamageAmount > 0 then   
            if self.ReflectorEntity != nil and self.ReflectorEntity == targetEntity then
               --> Last Impact         
               if masterDebug and myDebug then         
                  WARN('   LastImpact, returning false')
               end
               return false            
            elseif targetEntity.ProjectileReflector then               
               if masterDebug and myDebug then         
                  WARN('   Reflecting projectile')
               end
               --> Copy the basic data needed from the old projectile
               local dD = self.DamageData               
               dD.Launcher = self:GetLauncher()
               dD.bp = self:GetBlueprint().BlueprintId   
               local vX, vY, vZ = self:GetVelocity()
               local sX, sY, sZ = unpack( self:GetPosition() )
               local oX, oY, oZ = unpack( targetEntity:GetPosition() )
               local offsetX = sX - oX
               local offsetY = sY - oY
               local offsetZ =   sZ - oZ                                          
               --> Randomize the vector a bit so the child projectile doesnt always return down the original vector (Left and right spread)
               vX = utilities.GetRandomFloat( (vX * 0.800), (vX * 1.200) )                                     
               --> Reflected child projectile
               local reflectorProj = targetEntity:CreateProjectile( dD.bp, offsetX, offsetY, offsetZ, 0, 0, 0)
               WARN('   self launcher: ', self:GetLauncher():GetBlueprint().BlueprintId   )
               WARN('   reflectorProj launcher: ', reflectorProj:GetLauncher():GetBlueprint().BlueprintId )
               --> Remember what the projectile reflected from
               reflectorProj.ReflectorEntity = {}
               reflectorProj.ReflectorEntity = targetEntity
               --> Pass Damage Data
               reflectorProj.DamageData = dD                           
               --> Reflect the projectile
               reflectorProj:SetVelocity( -vX, -vY, -vZ )   
               reflectorProj:SetVelocity( 20 )
               reflectorProj:SetLifetime( 4 )            
               reflectorProj:SetVelocityAlign( true )
               if dD.Launcher != nil then
                  reflectorProj:SetNewTarget( dD.Launcher )
               end
               reflectorProj:TrackTarget( false )
               if masterDebug and myDebug then         
                  WARN('   Destroying old proj')
               end                                                                                                                           
                   self:Destroy()
                   return false
            end
         else
            if myDebug and masterDebug then
               WARN('   Projectiles used for props or effects detected')
            end   
         end      
      end                           
      --> Run old
      if myDebug and masterDebug then
         WARN('   Running oldProjectile.OnImpact')
      end                        
      oldProjectile.OnImpact(self, targetType, targetEntity)                  
   end,
}
end