Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

xSuiCidEx

weapon firing

This topic is 6818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

_ 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?

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!