#### Archived

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

# Total Forward Speed.

This topic is 5659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. In my game i need to work out the total velocity in one diretion. This isn''t the usual question of ''how do i move forward in the direction i''m facing'' but more of ''how do i get the total forward speed from 2 velocities?'' I have a 2D Vector (well its not a vector, it represents velocity) called TmpVel (with 2 components x and y) In my movement function this is modified to apply Forward and Reverse forces. Then to get the real position of the object it does this:
Velocity.x = TmpVel.x * cos(Rotation*3.1415926/180);
Velocity.y = TmpVel.y * sin(Rotation*3.1415926/180);

My question is how would i get the current total forward (or backward) or speed from those x and y values? Is it as simple as adding the two components together? I''m just checking this to make sure i do it right. I''ve been doing alot of searching over the gamedev forums and found many extreamly useful topics about this moving forward issue. Just not this. Thanks -J

##### Share on other sites
sqrt(velocity.x^2 + velocity.y^2) will give you the magnitude of movement.

##### Share on other sites
What Waverider said. It seems to me that all you want is the scalar speed value of the vector, and in general, the magnitude of a vector is given by

Sqrt(x_1^2 + x_2^2 + ... + x_n^2)

for any vector with n elements.

Proving this in the 2-dimensional case is very easy. Just use Pythagoras

##### Share on other sites
yeah, the reason you couldn''t find information on it is because it is a simple mathematical concept. Obviously you haven''t covered Pythagorean Theorem yet. =)

##### Share on other sites
I have, but I only remembered it for my math exam the other day, I need to brush up on mu trig math, the rest is ok..

-J

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×