Why is Bullet angle wrong?

Just started using Construct 2? Post your questions here

Post » 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
13
S
4
Posts: 280
Reputation: 1,578

Post » 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
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » 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
13
S
4
Posts: 280
Reputation: 1,578


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests