Enemy AI - Running away in 4 directions

Get help using Construct 2

Post » Tue Aug 20, 2013 10:06 pm

Hello! I am tying to make a top down 4 direction rpg style game and I am trying to come up with a way to make a certain enemy run away from the player in 4 directions. I assumed that I could tell the enemy sprite to compare it's location to the player and use that information to go the opposite direction.

Using the 8-direction behavior I have been able to successfully get two different results. While I have all for directions activated it seems that it only wants to slide left or right, or up and down. If i deactivate the events for up and down movement, the right and left will work correctly and vice versa. This lead me to believe that I was using the wrong approach. I have also tried using the bullet behavior with no avail. The farthest I have come Is this current .capx I have using 2 separate 8-direction behaviors for up and down, as well as left and right. This as you can see has yielded me results in which the enemy wants to move diagonally in 4 directions instead of up down left and right.

Any insight on a better approach to this problem would be greatly appreciated!

Here is the .capx
https://www.dropbox.com/s/tvrnsb2dovg3tks/enemy%20AI%20test.capx
B
9
S
2
Posts: 5
Reputation: 650

Post » Wed Aug 21, 2013 12:30 am

If you look at this, I've edited it so you can see why it's doing what it's doing. It's triggering UP+LEFT or DOWN+RIGHT at the same time which results in diagonal movement. This is because it doesn't check either X or Y, it checks both so if Enemy X and Enemy Y is more than Player X,Y it will move RIGHT+DOWN etc. You need to set up some logic so it only ever triggers the X or the Y.

If you can't come up with a way of doing this you could take another approach such as setting an invisible collision sprite pinned to the enemy and when player overlaps the top side the enemy does 8-direction movement down etc.plinkie2013-08-21 00:33:18
B
46
S
16
G
74
Posts: 2,088
Reputation: 44,185

Post » Wed Aug 21, 2013 4:26 am

@plinkie Thanks for the reply! I assumed that was the issue, and after working for a few hours and using the overlap at offset function i have seemingly been able to detect the direction that i am coming from, but for some reason i cant get the Boolean to trigger the 8-direction simulate control. i cant get it to trigger in the text boxes just fine but the red square stays at a halt. Even still, using the overlap seemed easier but for some reason i cant get the box to move using overlap at offset. It seems to work better at detection but i cant test it if it wont move.

Also I was wishing that I could somehow figure out how to use the OR blocks in a way that I could choose one or the other but i was have little to no luck trying to figure out how to set it up.

heres my capx if you want to see it again.

https://www.dropbox.com/s/dpta8brbtwj5yqs/enemyAImovement.capx
B
9
S
2
Posts: 5
Reputation: 650

Post » Wed Aug 21, 2013 4:48 am

It's not working because you've pinned the enemy to the sprite. You need to pin the sprite to the enemy!
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,852

Post » Wed Aug 21, 2013 6:06 am

*Headdesk*
Thank you so much! I had a feeling it was something really silly like thatdmandork2013-08-21 06:10:04
B
9
S
2
Posts: 5
Reputation: 650


Return to How do I....?

Who is online

Users browsing this forum: plinkie, rayolf, Yahoo [Bot] and 7 guests