Advertisement Jump to content


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


Setting a max velocity for asteroids style physics?

This topic is 5844 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
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:
-- 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


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 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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!