Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stranga on Mon 04/11/2019 05:50:17

Title: [SOLVED] Enemy attacking player
Post by: Stranga on Mon 04/11/2019 05:50:17
Hello everyone,

I'm in a bit of a pickle. I want to make the enemy attack the player but then pause for a few seconds then follow/attack again (sorta like invincible frames)

Code (ags) Select

function repeatedly_execute()
{
  cEnemy.FollowCharacter(player, 1, 100);
 
  if (cEnemy.IsCollidingWithChar(player))
  {
//Enemy Attacks!
      player.Tint(100, 0, 0, 100, 90);
      PlayerHealth -= 3; //Player takes damage
      cEnemy.Animate(0, 9, eOnce, eBlock, eForwards); 
      cEnemy.UnlockView(eKeepMoving);
      player.RemoveTint();
      tickspassed = 0;
  }
}


This is what I have so far(trying to keep things simple...if I can)
Any help will be greatly appreciated :)
Title: Re: Enemy attacking player
Post by: Slasher on Mon 04/11/2019 06:04:53
So, if cEnemy collides with the player cEnemy animates and the player loses health..

And you want to this to repeat?

You will probably need to move the player away just a little bit from cEnemy and have cEnemy again follow player...

I think this is what you mean... Or do you mean repeat actions a few times in succession?
Title: Re: Enemy attacking player
Post by: Stranga on Mon 04/11/2019 06:31:30
If cEnemy collides with player, cEnemy animates player loses health, then cEnemy can't move for a few seconds (giving the player a chance to move) then chases the player again.

I apologize if this was confusing.
Title: Re: Enemy attacking player
Post by: Slasher on Mon 04/11/2019 06:43:04
Maybe have the player walk say about 10 pixels away from cEnemy and have character repeat follow.... player will then only have a very short time to run away.

Food for thought...
Title: Re: Enemy attacking player
Post by: Stranga on Mon 04/11/2019 06:59:27
Is there a way to check how far cEnemy may be to the player?
Title: Re: Enemy attacking player
Post by: Slasher on Mon 04/11/2019 07:10:27
Quote from: Stranga on Mon 04/11/2019 06:59:27
Is there a way to check how far cEnemy may be to the player?

You have 1 pixel follow

cEnemy.FollowCharacter(player, 1, 100);

you could add a condition if enemy x from player then run collide script.

Title: Re: Enemy attacking player
Post by: Stranga on Mon 04/11/2019 08:04:02
thanks Slasher, that did the trick! :)