+2 votes

For a topdown shooter I have the direction a bullet should go and the amount of variance there should be. Assuming I have everything I need, what is the math to adjust the direction of the bullet according to the variance?

in Engine by (56 points)

You might want to be more specific regarding the form of the information you have.

  • direction of bullet: I assume that's either a Vector2 or Vector3?
  • amount of variance: Is that a distance at the impact point, an angle from the shoot point (in degrees or radians?), or something else?

Sure. So I have a direction Vector2 made from the position of the player to the position of the mouse. I then have a variance that is randomly picked from a range. It would be best for it to be from the position of the player. It is neither degrees or radians as of yet.

Maybe I'm not understanding something, but it seems like you could simply add the random variance to the position of the player, and then create a new Vector2 between the mouse and that new position, rather than your current Vector2 (which you say is between the mouse position and the player's position).

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.