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
255
S
32
G
13
Posts: 1,799
Reputation: 19,303

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
29
S
18
G
160
Posts: 894
Reputation: 83,386

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
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

Post » Sun May 17, 2015 6:14 am

@R0j0hound As usual R0j0 saves the day. Thanks man :)
Image
B
255
S
32
G
13
Posts: 1,799
Reputation: 19,303


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests