weapon firing
_ Try including the distance in your calculations. i.e. d=(x^2+y^2)^.5 (square root) Then divide it by the dimension of the mouse's location that corresponds to the value you will change each frame. Finally multiply that by the number of "pixels" (units) that you want it to move each second.
_ Err, gotta run! Could someone pick up on this?
_ Err, gotta run! Could someone pick up on this?
i have been thinking about weapon firing...i'm trying to get my ship to fire a weapon (a missle lets say) towards the mouse when clicked...but the problem i am having is with finding out the correct x and y values to move the weapon picture everyframe...i have the ship located in the middle of the screen and have the map scrolling around it...i have tried calculating the slope from where the mouse is pressed related to the ship in the middle of the screen...but i found that the weapon would move way to fast if it had a messy slope such as a 27/5 (rise of 27, run of 5)...because it would move up 27 pixels and to the right 5 pixels.....i was wondering if anybody had any ideas of how to slow it down or even a better method of doing this?
---===xxxx===---
----THE END----
---===xxxx===---
----THE END----
---===xxxx===---
I'll pick up on it, but kind of twist it a little.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement