🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
weapon firing
_ Err, gotta run! Could someone pick up on this?
First off, you want to store the speed (scalar) at which the weapon moves in a floating point variable that is the pixels to move per second (not frame!).
Then, when the person fires the weapon, you calculate the vector, normalize, and then multiple by the intended speed. The last two steps could be combined if you want.
Anyway, what you'll be left with is a vector containing the pixels to move per second in the X and Y direction. Then, every frame, just calculate the time delta (time since the last movement calculation), multiple that (which should be in seconds) by the speed vector, and add the result to the location of the weapon.
Although it can be done without vectors, this seems to be the most logical way of explaining it.
- Splat