How do I make a sprite move towards player using 8Direction?

0 favourites
  • 7 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • So at the moment I have the enemy events set up correctly to make the player loose health. Though I was wondering how I would make the enemies move towards the player using 8Direction movement?

    Would I set actions "angle toward (player.x, player.y)" and "Set 8Direction speed to 80" to an "enemy is on layer 1" event? I tried this, it did work although every time I was going towards the enemies they were going backwards and sliding across the level but always looking at the player (Or more specific they were sliding the direction I was walking). I have the settings setup so the screen follows the player. Thank you!

  • I actually do something similar for touch controls using 8 direction. Same principle.

    Pick a threshold (it will be an imaginary bounding box) for how close the enemies can get to the player. Say, if they get within 40 pixels of the player, they stop progressing. Otherwise, they keep moving.

    This is simple to set up. In this case, we decided threshold = 40.

    If player.X>enemy.X+threshold, simulate control "move right" for enemy.

    If player.X< enemy.X-threshold, simulate control "move left" for enemy.

    If player.Y>enemy.Y+threshold, simulate control "move down" for enemy.

    If player.Y<enemy.Y-threshold, simulate control "move up" for enemy.

    It will then move up, down, left, right, and any combination of those directions until it is within your threshold (40 pixels here). That way, they won't bunch up and overlap the player. You can have whatever offset you want.

  • I actually do something similar for touch controls using 8 direction. Same principle.

    Pick a threshold (it will be an imaginary bounding box) for how close the enemies can get to the player. Say, if they get within 40 pixels of the player, they stop progressing. Otherwise, they keep moving.

    This is simple to set up. In this case, we decided threshold = 40.

    If player.X>enemy.X+threshold, simulate control "move right" for enemy.

    If player.X< enemy.X-threshold, simulate control "move left" for enemy.

    If player.Y>enemy.Y+threshold, simulate control "move down" for enemy.

    If player.Y<enemy.Y-threshold, simulate control "move up" for enemy.

    It will then move up, down, left, right, and any combination of those directions until it is within your threshold (40 pixels here). That way, they won't bunch up and overlap the player. You can have whatever offset you want.

    This seems like exactly what I need! Though how does the player.X>enemy.X+threshold work in event sheet? (Sorry if I am being tedious I am just trying to learn new things in construct 2 which could hopefully help me later.)

  • I will note that if your enemies should never stop moving, bullet behavior may be more efficient.

    Though you can combine that with Turret...

    Here, I made a .capx!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I will note that if your enemies should never stop moving, bullet behavior may be more efficient.

    Though you can combine that with Turret...

    Here, I made a .capx!

    Ah thank you! This really helped me out!

  • > blah blah

    >

    This seems like exactly what I need! Though how does the player.X>enemy.X+threshold work in event sheet? (Sorry if I am being tedious I am just trying to learn new things in construct 2 which could hopefully help me later.)

    The bullet behavior example would certainly work. Here's the same thing done with 8 direction (I limited it to 45 degree movement intervals, but you can do what you want, of course).

    [attachment=0:30flhqrd][/attachment:30flhqrd]

  • So at the moment I have the enemy events set up correctly to make the player loose health. Though I was wondering how I would make the enemies move towards the player using 8Direction movement?

    Would I set actions "angle toward (player.x, player.y)" and "Set 8Direction speed to 80" to an "enemy is on layer 1" event? I tried this, it did work although every time I was going towards the enemies they were going backwards and sliding across the level but always looking at the player (Or more specific they were sliding the direction I was walking). I have the settings setup so the screen follows the player. Thank you!

    Just wondering.. Could it be that the 8-direction's controls are set to default, meaning that if you use the arrow keys to move the player, the enemies also move that way because they are controlled by those inputs as well?

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