Announcement

Collapse
No announcement yet.

Attack Hit Detection and Damage dealing to NPCs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Attack Hit Detection and Damage dealing to NPCs

    Ok so here is my current issue, it's also the last issue stopping me from having a completed framework (as far as i can tell)

    So i currently have two pawn classes. the player and the enemy NPC

    The enemy NPC's run around and try to bump into you to deal damage. this code works fine

    Code:
    event Bump(Actor Other, PrimitiveComponent OtherComp, Object.Vector HitNormal)
    {
     local Pawn HitPawn;
     HitPawn = Pawn(Other);
    
    
     if(HitPawn != None)
     {
     if( PlayerController(HitPawn.Controller) != None )
     {
     HitPawn.TakeDamage( 50, None, HitPawn.Location, vect(0,0,0) , class'UTDmgType_Lava');
    
     }
    
     }
    }
    when they hit the player the player gets hurt/dies

    I want the player to essentially "crash bandicoot" it up and spin into them to deal damage to them

    here is my current code for that

    Code:
       exec function Attack ()
         {
         `log("attacked");
         AttackAnim.PlayCustomAnim('AttackTest',1.0,0.2,0.2, false, true);
          attackcheck();
    
         }
         
         //the hit detection
         function attackcheck ()
         {
             local vector loc,norm, end;
             local TraceHitInfo hitInfo;
             local Actor traceHit;
    
             end = Location + normal(vector(Rotation))*564; //trace to "infinity"
             traceHit = trace (loc, norm,end, Location, true,,hitInfo);
    
             `log("tracing");
    
                  if (traceHit==none)
                  {
                     `log("nothing to hit");
                     return;
                  }
    
                  else
                  {
                     `log("Hit");
                      HitEffect();
                      
                  }
    
         }
    
          function HitEffect()
         {
              //the particle effect
               HitEmitter = Spawn(Class'EmitterSpawnable');
               HitEmitter.SetTemplate(ParticleSystem'FX_VehicleExplosions.Effects.P_FX_VehicleDeathExplosion',true);
    
               HurtRadius(500, 300, class'UTDamageType',1000.0, Location,,,True);
    
         }
    this works and spawns the particle effect and hurt radius but the HurtRadius ends up killing the player, not the NPC, but theres no way to call bump or touch as a function (to my understanding at least) so i'm at a bit of a loss as to how to deal damage to these NPC's in the playerpawn class without having to go through the whole "it's actually a really short range projectile weapon" business.

    so yeah any help in getting it so that when the tracing detects it's hit something to deal damage to that something would be great. i'm really at a loss as to go about doing it.

    any ideas/directions to go in/help is really appreciated

    #2
    You can override TakeDamage and add a check. If the player is doing the attack and the instigator is himself, then don't take damage.

    Comment


      #3
      If the player is doing the attack and the instigator is himself, then don't take damage.
      thanks, how would i do that exactly?

      Comment


        #4
        Originally posted by Bailey9000 View Post
        thanks, how would i do that exactly?
        If you are asking for basic variable comparison then you should start to learn about unrealscript:

        http://udn.epicgames.com/Three/Devel...chnology_ book

        Comment


          #5
          no i get how to do an if then else statement, i just have no idea what it is i'd be comparing. so if i'm overriding take damage, then where? then if i'm checking to see what the instigator is how do i get that value and compare it to the playerpawn to check it's the player.

          code just goes flying over my head

          Comment


            #6
            Originally posted by Bailey9000 View Post
            no i get how to do an if then else statement, i just have no idea what it is i'd be comparing. so if i'm overriding take damage, then where? then if i'm checking to see what the instigator is how do i get that value and compare it to the playerpawn to check it's the player.

            code just goes flying over my head
            Yes, those are very simple checks.
            If you are having problems with it you should study the tutorials and get more knowledge before checking here again.
            If not every single small step you are going to ask how to do it and get no progress at all.

            100GPing100 said:
            You can override TakeDamage and add a check. If the player is doing the attack and the instigator is himself, then don't take damage.
            So what is the check? If the player is doing the attack and the instigator is himself.
            So what do you check for?

            Do you know the function TakeDamage? Do you know the parameters of that? Do you know what an Instigator is? Have you tried searching for the Instigator declaring and read the description in the code by Epic?

            Have you actually tried anything at all?

            Comment


              #7
              So you can overwrite the takedamage function in your pawn class by pasting:

              Code:
              event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
              {
              }
              Inside this function you need to check the attacker, the 'instigated by'. You only want to take damage if the controller isn't the one controlling the pawn.
              Code:
              if(instigatedby != controller)
              {
              health -= damage;
              }

              Comment


                #8
                looked at tutorials, they have helped me set up the framework so far, they have not helped with this particular issue

                Have you actually tried anything at all?
                yes, and it didn't work, hence why i'm asking here, thank you for your remarkably helpful response.

                Comment


                  #9
                  thanks, i will give that a go

                  Comment


                    #10
                    Originally posted by Bailey9000 View Post
                    looked at tutorials, they have helped me set up the framework so far, they have not helped with this particular issue

                    yes, and it didn't work, hence why i'm asking here, thank you for your remarkably helpful response.
                    I gave you the name of the function you need to overwrite and the variable you are looking for as well as the place with it's description.
                    But you were only able to do something when someone simply pasted the function for you.

                    Comment


                      #11
                      Just because...
                      Code:
                      class PhysicalRepresentationOfThePlayer extends Pawn;
                      
                      /** apply some amount of damage to this actor
                       * @param DamageAmount the base damage to apply
                       * @param EventInstigator the Controller responsible for the damage
                       * @param HitLocation world location where the hit occurred
                       * @param Momentum force caused by this hit
                       * @param DamageType class describing the damage that was done
                       * @param HitInfo additional info about where the hit occurred
                       * @param DamageCauser the Actor that directly caused the damage (i.e. the Projectile that exploded, the Weapon that fired, etc)
                       */
                      event TakeDamage(int DamageAmount, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser) {
                          // Check if we're not damaging ourselves.
                          if (EventInstigator != Controller) {
                              // It's not us, so take the damage.
                              super.TakeDamage(DamageAmount, EventInstigator, HitLocation, Momentum, DamageType, HitInfo, DamageCauser);
                          }
                          
                          /* Other method: DamageType
                      
                          // Check if we're taking damage from the spinning thingy radial damage.
                          if (DamageType != class'SpinningThingyRadialDamageTypeClass') {
                              // We're not, so take the damage.
                              super.TakeDamage(DamageAmount, EventInstigator, HitLocation, Momentum, DamageType, HitInfo, DamageCauser);
                          }
                          */
                      }
                      
                      DefaultProperties {
                      }
                      You can also write your own radial damage method, but that's not required, now is it? no

                      Comment


                        #12
                        thanks man, that's pretty much what i've got working at the minute following leoalexus's example, but thanks for the help

                        Comment


                          #13
                          HurtRadius() already doesn't do damage to itself, so if you call that function in your pawn, rather than in your controller (i'm guessing that's where it is now), that should fix it as well.

                          Also, the parameters to HurtRadius() are:

                          PHP Code:
                          simulated function bool HurtRadius
                          (
                              
                          float                BaseDamage,
                              
                          float                DamageRadius,
                              class<
                          DamageType>    DamageType,
                              
                          float                Momentum,
                              
                          vector                HurtOrigin,
                              
                          optional Actor        IgnoredActor,
                              
                          optional Controller InstigatedByController Instigator != None Instigator.Controller None,
                              
                          optional bool       bDoFullDamage

                          so there's a way to specify an actor to ignore when dealing damage, as well.

                          Comment

                          Working...
                          X