# Proper way to calculate x and y components of two 2D vectors

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.

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?

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);

• 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. Aug 27, 2016 at 5:13
• 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)); Aug 27, 2016 at 6:38