How do I Make an Enemy Run Away?

0 favourites
  • 6 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • In my game I want one of my enemies run upto a player, hit them, then run off, then run back and hit them again and repeat. How would I go about that?

    Tagged:

  • You will need to have a list of actions for your enemy then apply the value to variable:

    0: run to player

    1: hit player

    2: run away

    If the variable = a number action, proceed enemy to do that action.

  • There are few ways to do so depending on how you want it

    You could use the los to detect when the player is close enough in viewing range

    or

    you can give your ai a number variable call it dist then make an every tick and do set dist to distance(player.x,player.y,enemy.x,enemy.y) then just compare the distance

    Or

    Make a If hit boolean then compare player.x to enemy. X then simulation control you could use timers to let them know how long to runaway for

  • You will need to have a list of actions for your enemy then apply the value to variable:

    0: run to player

    1: hit player

    2: run away

    If the variable = a number action, proceed enemy to do that action.

    That... didn't answer the question on how to do #2

  • There are few ways to do so depending on how you want it

    You could use the los to detect when the player is close enough in viewing range

    or

    you can give your ai a number variable call it dist then make an every tick and do set dist to distance(player.x,player.y,enemy.x,enemy.y) then just compare the distance

    Or

    Make a If hit boolean then compare player.x to enemy. X then simulation control you could use timers to let them know how long to runaway for

    Me realizing I forgot to mention it's 8 direction movement with the enemies being solid so they can't run through the player. Like if it were a platformer this would be easy, it's just the fact that it's 8 directions so I can't just say an X value or they'll have times where they're just trying to push into the player when they're supposed to be running away.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 8 directions maybe add a custom movement and have it move -15 to -25 pixels

    or

    try a car behavior use the back movement for that while checking the dist

    Or

    A dist check then make a compare x to player then movement

    Compare y to player

    Condition compare player y to enemy y

    Check dist maybe 600 then simulation the direction you want and use a boolean for the on hit it kind of the same for sidescroller but you just check the x and y and dist and simulate control

    there not a lot i can think of for 8 directions

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