# SOLVED Enemy distance from Player, target only those enemies

Get help using Construct 2

### » Sun May 24, 2015 4:05 pm

I'm detecting the distance from enemy to player. Once the enemy is close enough, I want it to move faster. However, instead of only those enemies (that are close enough) getting faster, all enemies get faster. How do I make it so that only those that are close go faster?

distance(Enemy.X,Enemy.Y,Player.X,Player.Y) < 200
Enemy > Set Bullet speed to 800

I guess one solution is to create a circle sprite around my Player and if the enemy is overlapping it, to change the speed, but I don't want to do that.
Last edited by jook00 on Mon May 25, 2015 12:19 am, edited 1 time in total.

B
69
S
23
G
3
Posts: 454
Reputation: 6,999

### » Sun May 24, 2015 4:11 pm

You are not picking an enemy in your event, therefor all enemy instances will respond to the action.

Simple solution would be to add a system for each enemy condition..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Mon May 25, 2015 12:08 am

@littlestain, what would be the best way to add a system for each enemy condition?

B
69
S
23
G
3
Posts: 454
Reputation: 6,999

### » Mon May 25, 2015 12:20 am

I figured it out. I set distance as an instance variable for each enemy. When i compared the instance variable is less < 200, then it updated the speed.

B
69
S
23
G
3
Posts: 454
Reputation: 6,999

### » Mon May 25, 2015 12:29 am

You could give each of your enemies a variable

0=slow
1=fast

If enemy is <100 of Player.x+100 Player.Y+100 Set Variable 1
If enemy is >100 of Player.x+100 Player.Y+100 Set Variable 0

With these you can set the range, and the rate at which it increases for each enemy.

Not sure if this is what you wanted but thought id give it a shot.
B
9
S
3
Posts: 104
Reputation: 1,033

### » Mon May 25, 2015 3:58 am

@frostein Thanks! That works too!

B
69
S
23
G
3
Posts: 454
Reputation: 6,999