# Why is Bullet angle wrong?

Just started using Construct 2? Post your questions here

### » Sun Jan 04, 2015 3:48 am

I have a top-down game. 384/128 is a position directly above (North) of the Worker sprite. But when I click the Worker it moves to the right (East). The angle calcs to -90, why not 0? Why is the angle calculation not working?...

CaptureAngleQuestion.PNG
You do not have the required permissions to view the files attached to this post.
B
14
S
4
Posts: 300
Reputation: 1,643

### » Sun Jan 04, 2015 5:04 am

-90 is correct, since -90 is up. The issue is when the bullet behavior has a speed of zero, then setting the angle of motion has no effect, it will always become 0 (right). The solution is to set the speed first, then the angle of motion.

The reason behind this is the bullet behavior stores velocity in two variables: vx and vy, the first being for horizontal velocity and the other for vertical. When the speed is zero then:
vx=0
vy=0

The angle of motion is set by first calculating the current speed with the Pythagorean theorem: speed=sqrt(vx^2+vy^2)
next the new velocity is set in the angle you want:
vx = speed*cos(angle)
vy = speed*sin(angle)

But since the speed is zero vx and vy will become zero.
B
94
S
33
G
123
Posts: 5,454
Reputation: 78,471

### » Sun Jan 04, 2015 5:08 am

@R0J0hound That was it. Thanks for the extra detail. It actually makes sense when you see that. Thank you!!!!
B
14
S
4
Posts: 300
Reputation: 1,643