Deflector Shields

Talk about general things concerning Forged Alliance Forever.

Moderators: FtXCommando, Ze Dogfather

Deflector Shields

Postby Resin_Smoker » 02 Feb 2014, 20:47

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
Last edited by Resin_Smoker on 06 Mar 2014, 19:29, edited 2 times in total.
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Deflector Shields

Postby Golol » 03 Feb 2014, 08:08

lets put it on asf. it sure is going to help the performance :P.
User avatar
Golol
Contributor
 
Posts: 700
Joined: 07 May 2012, 15:56
Has liked: 24 times
Been liked: 21 times
FAF User Name: Golol

Re: Deflector Shields

Postby Krapougnak » 03 Feb 2014, 14:46

After Domino, you.
Welcome back Resin you were sorely missed ! 8-)
User avatar
Krapougnak
Contributor
 
Posts: 340
Joined: 12 Jul 2012, 11:03
Has liked: 193 times
Been liked: 24 times
FAF User Name: Krapougnak

Re: Deflector Shields

Postby lextoc » 03 Feb 2014, 15:03

Very nice, you can send them in huge armies hehe
I'm watching you!
User avatar
lextoc
Supreme Commander
 
Posts: 1057
Joined: 17 Mar 2013, 18:08
Has liked: 287 times
Been liked: 227 times
FAF User Name: lextoc

Re: Deflector Shields

Postby Seriph » 03 Feb 2014, 15:45

Make the projectiles reflect in "random" pattern so you can't have a deflector kill a fatboy by bouncing his projectiles back at him.
Seriph
Crusader
 
Posts: 18
Joined: 30 Oct 2013, 11:49
Has liked: 2 times
Been liked: 2 times
FAF User Name: Seriph

Re: Deflector Shields

Postby Resin_Smoker » 03 Feb 2014, 23:25

Krapougnak wrote:After Domino, you.
Welcome back Resin you were sorely missed ! 8-)


Thank you!
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Deflector Shields

Postby Resin_Smoker » 03 Feb 2014, 23:26

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
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Deflector Shields

Postby Resin_Smoker » 03 Feb 2014, 23:27

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
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Deflector Shields

Postby Resin_Smoker » 12 Feb 2014, 15:36

I've a functional script now!
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Deflector Shields

Postby Resin_Smoker » 14 May 2014, 08:21

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
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Next

Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 1 guest