# Common problem with angles I forgot how to solve...

Get help using Construct 2

### » Sat May 16, 2015 11:35 pm

I have an enemy that teleports around the player and shoots a bullet at you using angle(x1,y1,x2,y2). However, I want to limit the angle to -80 and +80 of the enemy's current angle so it's always shooting outwards / the bullet never overlaps the enemy itself, which I'm using clamp() for. This causes some problems because of the way angles work...i.e. if the enemy's angle is 270 (upwards) and the player is to the bottom left of it, it'll actually shoot as far to the right as it can instead of the left.

Any idea what to do about that? I remember MMF having an extension for this very thing...
B
246
S
30
G
13
Posts: 1,788
Reputation: 18,847

### » Sat May 16, 2015 11:53 pm

have you tested this pseudo code?

set angle random (max(-80,angle(x1,y1,x2,y2)),min(angle(x1,y1,x2,y2),80))
B
27
S
16
G
147
Posts: 884
Reputation: 76,696

### » Sun May 17, 2015 3:39 am

After you create the bullet and the enemy with the same angle as the enemy then this action should do it.
Bullet: Rotate min(80, anglediff(angle(enemy.x,enemy.y,player.x,player.y), enemy.angle)) degrees toward (player.x, player.y)
B
94
S
33
G
125
Posts: 5,458
Reputation: 79,979

### » Sun May 17, 2015 6:14 am

@R0j0hound As usual R0j0 saves the day. Thanks man
B
246
S
30
G
13
Posts: 1,788
Reputation: 18,847