Jump to content
  • Advertisement

Archived

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

starstriker1

Setting a max velocity for asteroids style physics?

This topic is 5750 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

My game is finally kicked off. I now can fly a ship around, shoot bullets, bounce off walls, etc... theres even a trail following my ship (when I thrust, of course). However, since this game uses asteroids physics, you could theoretically build up speed forever (or at least into an interviening obstacle got involved). How do I use a max_speed variable to lock the velocities to a certain level? In my last game (which I''m remaking), I used a simple, fast system where it checked x and y velocity against the max speed. This ws effective, except that it allowed you to gain more velocity by flying at an angle... How should I lock down the max speed?

Share this post


Link to post
Share on other sites
Advertisement
Well, I assume you''re storing asteroid velocity as velocity in the x and y axis- Since this is the case, you can get the asteroid''s total velocity with the square root of (X velocity)^2 + (Y velocity)^2 (more commonly known as the Pythagorean Theorem), and then compare that against the terminal velocity. That will pretty much re-compose the vector you want to look at, and give you its'' magnitude.

When you''re updating speeds, the best way to do "choke off" the velocities is probably to tell if the update will push the speed over the maximum, and then not update if it will.

- HC

-- EMail: cloweh@rpi.edu
-- AIM: SeigfriedH

Share this post


Link to post
Share on other sites
I''ve had this same problem in my game. Someone helped me and told me to do this:

totalvel = sqrt(xvel ^ 2 + yvel ^ 2)
if totalvel > maxvelocity

then

xvel = xvel / totalvelocity
yvel = yvel / totalvelocity
xvel = xvel * maxvel
yvel = xvel * maxvel

And you''ll get what you want

*Shameless plug* My game is at www.gamescreche.has.it if you want to check it out Name is Beyaan */Shameless plug*

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!