Enemy AI - Running away in 4 directions

0 favourites
  • 5 posts
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • 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


  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.


  • <img src="smileys/smiley2.gif" border="0" align="middle" /> It's not working because you've pinned the enemy to the sprite. You need to pin the sprite to the enemy!

  • *Headdesk*

    Thank you so much! I had a feeling it was something really silly like that

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