Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2D Vector bullshit

Name: Anonymous 2008-11-14 6:04

I've got 2 points (ie. X,Y vectors), and I need to find out the angle (degrees°) between them, so I can move an object which is at one of the points towards the other point.

How do I calculate the degrees plz???

Name: noobular 2008-11-17 8:02

WAIT NO

It doesn't work when the target vector is to the left of my current position vector.

/** Move ()
 *
 * Move the object towards its vector.
 *
 */
void Object_t::Move()
{
     Velocity.x = thrust * cos(headingDegs);
     Velocity.y = thrust * sin(headingDegs);

     Vector += Velocity;
}



/** GetDegrees ()
 *
 * Set headingDegs based on Target vector.
 *
 */

void Object_t::GetDegrees()
{
     float dx, dy;

     if (Target.y > Vector.y)
        dy = Target.y - Vector.y;
     else
        dy = Vector.y - Target.y;

     if (Target.x > Vector.x)
        dx = Target.x - Vector.x;
     else
        dx = Vector.x - Target.x;


     headingDegs = atan(dy / dx);
}



If I add this part to the end:

if (Target.x < Vector.x)
   headingDegs -= DEG2RAD(180);


it will work for targets that are left & up, but not left & down.  WHAT DO I DO LOL?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List