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

Get help using Construct 2

Post » Thu Feb 12, 2015 11:15 pm

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!
B
3
Posts: 6
Reputation: 187

Post » Thu Feb 12, 2015 11:39 pm

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.
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

Post » Thu Feb 12, 2015 11:56 pm

C-7 wrote: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.)
B
3
Posts: 6
Reputation: 187

Post » Fri Feb 13, 2015 2:18 am

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! :D
You do not have the required permissions to view the files attached to this post.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Fri Feb 13, 2015 6:16 am

Unnatural20 wrote: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! :D


Ah thank you! This really helped me out! :D
B
3
Posts: 6
Reputation: 187

Post » Fri Feb 13, 2015 5:01 pm

FroddeB wrote:
C-7 wrote: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).

attackTri8.capx
You do not have the required permissions to view the files attached to this post.
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

Post » Thu Feb 19, 2015 3:27 am

FroddeB wrote: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?
B
83
S
20
G
6
Posts: 175
Reputation: 8,131


Return to How do I....?

Who is online

Users browsing this forum: SneakyHands and 7 guests