Jump to content
  • Advertisement
Sign in to follow this  
Ahl

Determining speed in X/Y

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

I have an asteroids style game in the making and i'm wondering if there is a better way to go about some things: x_new_speed -= float(cos(self.facing * NEW_PI) * (self.is_accel * self.accel_rate * time_multiplier)) y_new_speed += float(sin(self.facing * NEW_PI) * (self.is_accel * self.accel_rate * time_multiplier)) This accelerates the ship according to the direction its facing. To determine the ships present speed I add x_new_speed and y_new_speed then divide by two but that doesnt sound right to me. If I'm traveling along x at 100 and y by 1 my math gives me roughly 50 but it's obviously moving faster then that. What is a better way to go about determining speed? Thx in advance. -Ahl

Share this post


Link to post
Share on other sites
Advertisement
In other words (if I understand correctly), you take the average of the x- and y- components to get the speed of the object?

I believe that speed is rather:

square_root(x_component2 + y_component2).


This is essentially the Pythagorean Theroem - the two components can be seen as the two perpendicular sides of a right-angled triangle, with the speed being given by the length of the hypotenuse.

(This is also a matter of vector mathematics; if you haven't yet encountered that, then I suggest that you look into it - it can be quite useful for these things, I find.)

Share this post


Link to post
Share on other sites
Now that I see it that makes total sense. I don't know why I didn't think of that.

Thank you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!