How do I make enemies "run" away from the player?

0 favourites
  • 3 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Imagine as if they were afraid of the character, and I have the line of sight stuff down and everything, I just need to know specifically the coding that says "go the direction the opposite of the thing you are running from"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • create an instace variable (state) to store the enemy state

    On line of sight compare the angle from enemy to player angle(enemy.X,enemy.Y,player.X,player.Y) and based on this result, change the enemy.state to running_away_left ... running_away_right

    If enemy.state = running_away_right Set enemy.position to Self.X + 1

    You need also a condition to stop it and change the enemy.state

  • create an instace variable (state) to store the enemy state

    On line of sight compare the angle from enemy to player angle(enemy.X,enemy.Y,player.X,player.Y) and based on this result, change the enemy.state to running_away_left ... running_away_right

    If enemy.state = running_away_right Set enemy.position to Self.X + 1

    You need also a condition to stop it and change the enemy.state

    This however lends itself for some issue, when the player is turned with his back to the enemy. The enemy would run at the player in this matter..

    A simple compare,

    Enemy.X < Player.X (enemy is on the left of the player)

    Enemy.X > Player.X (enemy is on the right of the player)

    Gives you a clear indication on which side the enemey and players are, run away appropiately.

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