How do I make an enemy only attack the player when he is at X distance away from him? [SOLVED]

Not favoritedFavorited Favorited 0 favourites
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hi guys!

    In Construct 2, I'm trying to implement in the AI ​​of a wandering enemy the reaction of attacking the player only when it sees the player (Line of Sight), which activates a "state" instance variable (alert) and finally is at a distance X from the player.

    As shown in the image, I tried using "Compare two values", "Pick by comparision" and "Is overlapping at offset" and I couldn't.

    Thanks one more time!

  • Hello, you need to use the "For Each" condition at top of event 27 to be able to pick the enemies correctly and compare their distance separatly

  • Hello, you need to use the "For Each" condition at top of event 27 to be able to pick the enemies correctly and compare their distance separatly

    I tried here, but it still doesn't works. :(

  • What are the events for the ATTACK state of an enemy? This is probably where the problem is

  • What are the events for the ATTACK state of an enemy? This is probably where the problem is

    Follow below:

  • I see many issues in your events logic, can you describe me how your enemies are supposed to behave exactly? I'll make an example capx, that will be easier than writing an essay;

    If possible link me your capx file, that'll be faster to edit

  • I see many issues in your events logic, can you describe me how your enemies are supposed to behave exactly? I'll make an example capx, that will be easier than writing an essay;

    If possible link me your capx file, that'll be faster to edit

    Sure, I can explain it to you, man. :)

    My enemy have many behavior states: idle, walk, alert and attack.

    He usually stands still (idle) and becomes alert when he sees the player from a certain distance (Line of Sight and then alert state). Then he follows the player and delivers a heavy attack on them (his only attack, slow and strong). He only attacks when he is a certain distance away from the player.

    These player boolean instance variables are to prevent the player from attacking when he is being attacked. :)

  • So the enemy stays still, enters a short ALERT phase when detecting the player, then start moving toward them; Once close enough, if the player is not attacking already, the enemy will attack, did I get everything right?

  • So the enemy stays still, enters a short ALERT phase when detecting the player, then start moving toward them; Once close enough, if the player is not attacking already, the enemy will attack, did I get everything right?

    Exactly that! :D

  • And what about the "Pick at random" condition? What's the effect you're trying to achieve with it?

    Also what's the Line of Sight reach?

  • And what about the "Pick at random" condition? What's the effect you're trying to achieve with it?

    Also what's the Line of Sight reach?

    I already tried it and don't worked. :(

  • No i mean, was it meant to activate a random enemy if many enemies are on screen?

    Also, what's the Line of Sight distance you used?

  • No i mean, was it meant to activate a random enemy if many enemies are on screen?

    Also, what's the Line of Sight distance you used?

    For now, this enemy only appears alone in a stage/layout. The Line of Sight range is 500.

  • Alright I made an example capx, feel free to change the distance/speed values to fit your needs, but that should solve your problem (works with multiple enemies instances) :

    drive.google.com/file/d/1F5L75Z0UjxcNAGX2NukdTzTFaiYE7p7O/view

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Alright I made an example capx, feel free to change the distance/speed values to fit your needs, but that should solve your problem (works with multiple enemies instances) :

    https://drive.google.com/file/d/1F5L75Z0UjxcNAGX2NukdTzTFaiYE7p7O/view?usp=sharing

    Thanks, man! I'll test and study it right now! :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)