I’m trying to make a game where the bullets can fly in any direction. I would ike to make them vectors with a direction and magnitude to make them go the direction. I’m just not sure how to implement this?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are two parts that need to be calculated. First, I’d start off with the total distance. This should be straightforward:
Assuming this is a 2D game, you should then use sine & cosine to break the total distance up into the X and Y components (for a given angle):
Finally, the distance x/y should be offset based on the starting position of the bullet:
Of course, you could wrap all of this in a nice class, expanding & polishing as needed.