Does anyone know how to create a routine that orders enemies by proximity to the player character?

0 favourites
  • 12 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hi guys!

    I'm trying to implement a routine for my top-down game, in which a flying enemy activates disabled enemies near the player character, in order of proximity.

    I tried to create a routine with the help of ChatGPT, but I believe he made mistakes in some commands (but he was right when recommending the use of Array).

    Below is an image so you can better understand the mechanics I am trying to program.

    Tagged:

  • If you just want to pick the closest enemy then:

    Enemy: pick closest to (player.x, player.y)

    Or if you want to pick all the enemies within a certain distance of the player:

    System: pick by comparison: enemy: distance(enemy.x,enemy.y,player.x,player.y)<100

    I personally wouldn’t want to touch any code that ai generates. Mainly because debugging is hard and time consuming. I find it easier to try to understand what I code as I go so I’m able to fix things as I go. I have no way of verifying how correct, robust or bug free a piece of ai code is without dissecting it which sounds like an annoying waste of time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you just want to pick the closest enemy then:

    Enemy: pick closest to (player.x, player.y)

    Or if you want to pick all the enemies within a certain distance of the player:

    System: pick by comparison: enemy: distance(enemy.x,enemy.y,player.x,player.y)<100

    I personally wouldn’t want to touch any code that ai generates. Mainly because debugging is hard and time consuming. I find it easier to try to understand what I code as I go so I’m able to fix things as I go. I have no way of verifying how correct, robust or bug free a piece of ai code is without dissecting it which sounds like an annoying waste of time.

    Thanks, dude!

    I want the routine to calculate the distance of each enemy to the player character and the drone (the green square) to activate them in an order of proximity.

  • System: pick by comparison: enemy: distance(enemy.x,enemy.y,player.x,player.y)<100

    In this case, is it better for enemies to be alone or grouped together in a family?

  • If you just want to pick the closest enemy then:

    Enemy: pick closest to (player.x, player.y)

    Or if you want to pick all the enemies within a certain distance of the player:

    System: pick by comparison: enemy: distance(enemy.x,enemy.y,player.x,player.y)<100

    I personally wouldn’t want to touch any code that ai generates. Mainly because debugging is hard and time consuming. I find it easier to try to understand what I code as I go so I’m able to fix things as I go. I have no way of verifying how correct, robust or bug free a piece of ai code is without dissecting it which sounds like an annoying waste of time.

    It's working!

    You are the man!

  • R0J0hound Sorry to bother you again, but now I have a new question: how do I make the green box activate only the enemy touched by it (it's also the one closest to the player character)?

    In the current routine, the box activates them all after touching one of them. I tried several alternatives (using UID, pick random instance, pick nearest), but still without success. :(

  • Add another condition to the event: green overlaps enemy?

  • An example might be close to what you are looking for: dropbox.com/scl/fi/futhyhxo5wbfz4txot0rw/4-direction-chase-avoid.capx

  • R0J0hound alextro

    I managed to implement this last night, using Overlapping + Pick random instance + Pick instance with UID. You two are awesome!

    Thanks again for all attention and support! :D

  • An example might be close to what you are looking for: dropbox.com/scl/fi/futhyhxo5wbfz4txot0rw/4-direction-chase-avoid.capx

    It's a good solution, man. Thanks again! :D

    It will work well with some enemies.

    My big challenge now is being able to implement an enemy AI that actually pursues the player on the stage, whether or not it may find the shortest route. And most importantly, it doesn't get stuck on the walls. ^^

  • Use "For each (ordered)" condition

  • Use "For each (ordered)" condition

    Thank you very much! :D

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