# How do I make enemies oscillate around the player?

Get help using Construct 2

### » Thu Jul 17, 2014 6:22 am

I saw a post about a whole ago but in 1 hour I couldn't find again so maybe someone can help me out. I got a top down game with spaceships. I will like the enemies to come towards the player and when they are in a defined range I'll like for them to start making circles around the player.

Any suggestions?
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
45
S
10
G
1
Posts: 195
Reputation: 3,575

### » Thu Jul 17, 2014 7:02 am

for each enemy
system compare two values: distance(enemy.x,enemy.y,player.x,player.y) => 100
enemy - move towards player.x,player.y

for the second part I would have a rotating sprite at the players position and pin the enemy to it (trigger once), when distance is less then 100, but there are probably better solutions..
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

### » Thu Jul 17, 2014 7:11 am

LittleStain wrote:for each enemy
system compare two values: distance(enemy.x,enemy.y,player.x,player.y) => 100
enemy - move towards player.x,player.y

for the second part I would have a rotating sprite at the players position and pin the enemy to it (trigger once), when distance is less then 100, but there are probably better solutions..

Thank you very much. I will try it when I get home and will upload the events when finished in case someone needs them too.
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
45
S
10
G
1
Posts: 195
Reputation: 3,575

### » Thu Jul 17, 2014 9:24 am

Okey I done something else, made a rotating sprite and assigned the enemy to use pathfinding towards an image point set at the corner. It has several drawbacks, such as if the solid state is added to the player it cannot move.

How it looks like:

Code:
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
45
S
10
G
1
Posts: 195
Reputation: 3,575

### » Thu Jul 17, 2014 9:26 am

I'm gonna search for a smoother and better option. Till then I'm all ears for suggestions
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
45
S
10
G
1
Posts: 195
Reputation: 3,575

### » Thu Jul 17, 2014 9:41 am

enemy now has both pathfinding and bullet behaviour..
I don't think that is advisable..

Also I guess using pathfinding both on the player and the enemy (the enemy refreshing every 0.1 second) might not be a good move performance-wise, but you'll have to check in the debugger for that..
Last edited by LittleStain on Thu Jul 17, 2014 9:46 am, edited 1 time in total.
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

### » Thu Jul 17, 2014 9:42 am

The bullet behaviour was disabled at start, sorry.
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
45
S
10
G
1
Posts: 195
Reputation: 3,575

### » Thu Jul 17, 2014 10:55 am

I created the same kind of behaviour with a simple bullet behaviour
- once your enemy is in circling distance of the player:
- set the enemy's direction to look at the player and imediately add an offset of 90 degrees to that angle
- move the enemy forward
=>because you constantly readjust the lookAtPlayer+90DegreeOffset, the enemy will always move sidewards to the player, effectively circling the player
B
17
S
8
Posts: 262
Reputation: 2,211

### » Thu Jul 17, 2014 11:01 am

facecrime wrote:- once your enemy is in circling distance of the player:

How did you do that? I only have some complex solutions to finding the circling distance. Think you can post a screenshot of your events?

Thanks.
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
45
S
10
G
1
Posts: 195
Reputation: 3,575

### » Thu Jul 17, 2014 11:07 am

You could do it through some expression in a 'Pick' event i believe
or
just use the Line Of Sight behaviour, that also has a range. can even be set 360 degrees if needed

havent got the file aruond for screenshots sry
B
17
S
8
Posts: 262
Reputation: 2,211

Next