Jump to content
  • Advertisement
Sign in to follow this  
Hacktank

Combining Directional Speed

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

Hello, I am trying to combine directional speed. For example if a gameobject is has a speed of 10 and a direction of 90 degrees (i use radians but for the purposes of example simplicity im using degrees) and I try to apply downward speed (for example 15 speed, 270 degrees for example), this should end up with a speed of 5 at 270 degrees. But how would i actually calculate this? And on a side-note how would i go from speed/direction to x and y speed and the other way around? Thank You. [Edited by - Hacktank on April 16, 2010 5:17:10 PM]

Share this post


Link to post
Share on other sites
Advertisement
You add vectors.

Vectors can be represented in polar coordinates or rectangular coordinates.

Your representation (angle,radius) is polar coordinates. You can use the law of cosines to add vectors in that representation if you choose, but it is much,much easier to convert the representation to rectangular (x,y) and add them in that representation.

To do the conversion, given (angle,radius) = (theta,phi)

x=radius*cos(theta);
y=radius*sin(theta);

the opposite conversion is
radius=sqrt(x*x+y*y);
theta=atan2(y,x);


to add two vectors in rectangular,
x=x1+x2;
y=y1+y2;

Share this post


Link to post
Share on other sites
You add vectors.

Vectors can be represented in polar coordinates or rectangular coordinates.

Your representation (angle,radius) is polar coordinates. You can use the law of cosines to add vectors in that representation if you choose, but it is much,much easier to convert the representation to rectangular (x,y) and add them in that representation.

To do the conversion, given (angle,radius) = (theta,phi)

x=radius*cos(theta);
y=radius*sin(theta);

the opposite conversion is
radius=sqrt(x*x+y*y);
theta=atan2(y,x);


to add two vectors in rectangular,
x=x1+x2;
y=y1+y2;

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.

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!