How do I make enemies stop once they get near the player?

0 favourites
  • 5 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Hi everyone,

    I have a simple test for a game I am developing. I have enemies with path-finding and LOS setup that is working as expected. The problem comes when the enemies got to close or overlaps the player. They usually path-find to the player and end up circling the player, and eventually end up pointing away from the player and lose LOS and run away. I am trying to make them stop when they get close (and later play an attack animation) then go after the player again once the player moves. I thought I had it working, but sometimes the enemy will get stuck and not move until another event is triggered. Any suggestions are appreciated. I can post my file if it will help diagnose the problem.

    Thanks,

  • Actually here's the latest version

    Edit: not high enough rep to post url

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try to directly upload the file or add some spaces into the URL that the system does not recognise your link as a link

    As a possibility on how to achieve what you want. Add an instance variable to your enemies (could be a boolean that you could call "near player"). When the enemy is near your player set it to true and if not, set it to false. To your moment events, just add a check on if the variable true or false. If it is false, do movement, if it is true, do something else.

  • Thanks Ubivis,

    Sorry it took so long to get back to this post. I actually tried the "near player" variable, but I think my events were off a bit so I deleted them. I will attach the file if you want to take a look. I probably need to pay more attention to my conditions for each movement type.

  • Well it seems my for each loop was the cause of the problem. Does the for each start a separate loop per instance or run it for one then start the it for the next instance and repeat? Before I added the for each my enemies were sharing certain variables like "alerted", maybe it was fixed with the last update. Anyway I attached my new file if anyone wants to see it.

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