Determining speed in X/Y

Started by
2 comments, last by Thaumaturge 16 years, 2 months ago
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
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.)

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

Now that I see it that makes total sense. I don't know why I didn't think of that.

Thank you.
'Tis my pleasure - good luck with your project. ^_^

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement