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

Get help using Construct 2

Post » Wed May 07, 2014 11:39 pm

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,
B
6
Posts: 11
Reputation: 272

Post » Thu May 08, 2014 12:24 am

Actually here's the latest version :D

Edit: not high enough rep to post url :(
B
6
Posts: 11
Reputation: 272

Post » Thu May 08, 2014 8:58 am

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.
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Mon May 12, 2014 11:35 pm

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.
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 11
Reputation: 272

Post » Tue May 13, 2014 12:08 am

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.
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 11
Reputation: 272


Return to How do I....?

Who is online

Users browsing this forum: grigrizljac, korbaach and 17 guests