Need help with Vector3s and Vector2s

Hi there,

(I have edited this post to make it more understandable).

In the following diagram, I have 2 Vectors - Vector A and Vector B. I want to find Vector C.

Is there a way to do this? / Is there a way to specific the vector using Transform Direction rather than forcing VectorA to be the transform of some object?

(P.S. Im using C#, and whilst Vector A and C will be Vector3s, VectorB will be a vector2).
(Currently in my game VectorA represents a special unique Vector to do with my scene camera, VectorB represents a player’s input using the analogue sticks, and VectorC is supposed to represent a direction for that player’s character to be moving).

Using Vector3.up as the reference vector for the angle, we can do this:

Quaternion q = Quaternion.FromToRotation(Vector3.up, v3B);
Vector3 v3C = q * v3A;

Where v3A, v3B, and v3C are the vectors A, B, and C from your diagram.

Transform.TransformDirection is equivalent to Transform.localToWorldMatrix.MultiplyVector.

You need to decide what axes B is expressed in. Without having your axes labeled, I’m going with the assumption that your vertical axis is Y and your horizontal is X.

B will be defined in a space where A is Y. The X axis is trivially found in 2D. Then you create a 2x2 matrix with these vectors as the columns, and you can transform local vectors to world ones. Matrix4x4.MultiplyVector is overkill, because it handles up to 3 dimensions of rotation; if it matters for performance, you can make your own Matrix2x2 struct.

[SerializeField] Vector3 a;
[SerializeField] Vector2 b;

void OnDrawGizmos() {
	Vector2 ay = ( (Vector2)a ).normalized;
	Gizmos.color = Color.green;
	Gizmos.DrawRay(Vector3.zero, ay);

	Vector2 ax = new Vector2(ay.y, -ay.x);
	Gizmos.color = Color.red;
	Gizmos.DrawRay(Vector3.zero, ax);

	Matrix4x4 aToWorld = new Matrix4x4();
	aToWorld.SetColumn(0, ax);
	aToWorld.SetColumn(1, ay);
	Vector3 b_world = aToWorld.MultiplyVector(b);
	b_world.z = a.z;	// I don't know if this is what you want.
	Gizmos.color = Color.cyan;
	Gizmos.DrawRay(Vector3.zero, b_world);
}