Why is Bullet angle wrong?

0 favourites
  • 3 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • 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?...

    [attachment=0:55hdm4g4][/attachment:55hdm4g4]

  • -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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound That was it. Thanks for the extra detail. It actually makes sense when you see that. Thank you!!!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)