I'm having some issues on resolving this with the current set of Vector2 methods. Could you help me to define a universal solution? The idea is to move a spaceship to another point using only relative to (A) lateral and forward movements.

enter image description here

Given two points A(1,-1) and B(2,-3): - A has a known angle with the y axis: alpha - How to calculate the x-dist and y-dist relative distances in order to move A to B?


1 Answer 1


Use the dot product to find how far along the normal a vector is

float Y_dist = Vector2.Dot(B - A, thatBigArrow.normalized);

And the rotated vector for the other direction:

// calculate rotated vector by 90 degrees: (y, -x)
Vector2 x_direction = new Vector2(thatBigArrow.y, -thatBigArrow.x);

float X_dist = Vector2.Dot(B - A, x_direction.normalized);
  • \$\begingroup\$ Sorry maybe I haven't been very clear. The big arrow is not a vector, it's just the angle [0-360] the aircraft is facing in the world. So the lateral movement has to be perpendicular to this angle. Could you extend your answer having just two vectors A, B and the azimuth of A. \$\endgroup\$
    – Veilkrand
    Aug 27, 2016 at 5:13
  • \$\begingroup\$ So in my case, using 0-259 degrees of heading [-1,1], the direction vector will be: Vector2 directionVector = new Vector2 (Mathf.Sin (heading * Mathf.Deg2Rad), Mathf.Cos (heading * Mathf.Deg2Rad)); \$\endgroup\$
    – Veilkrand
    Aug 27, 2016 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .