[SOLVED] Enemy attacking player

Started by Stranga, Mon 04/11/2019 05:50:17

Previous topic - Next topic

Stranga

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

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 :)

Slasher

#1
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?

Stranga

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.

Slasher

#3
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...

Stranga

Is there a way to check how far cEnemy may be to the player?

Slasher

#5
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.


Stranga

thanks Slasher, that did the trick! :)

SMF spam blocked by CleanTalk