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

Get help using Construct 2

Post » 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...
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » 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))
Image Image
B
25
S
14
G
137
Posts: 876
Reputation: 71,505

Post » 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
92
S
32
G
110
Posts: 5,295
Reputation: 71,501

Post » Sun May 17, 2015 6:14 am

@R0j0hound As usual R0j0 saves the day. Thanks man :)
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo, Jackriduk, kiki4construct and 23 guests