Jump to content
• ### What is your GameDev Story?

• Advertisement

#### Archived

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

##### 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

##### 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

##### Share on other sites
Yes, I was aware of the pythagorean theorum... very nice stuff, trig is! :D

Thanks, Zeraan... that worked beautifully.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 15
• 10
• 9
• 35
• 16
• Advertisement
• ### Forum Statistics

• Total Topics
634125
• Total Posts
3015677
×

## Important Information

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

GameDev.net 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!