# Compute the difference between two vector3 and iterate with the difference in mathematically

I have two eularAngle vector3 A , and vector3 B;

I want to rotate the vector3 A rotate to vector3 B by 10 small steps;

for (int i = 0; i < 10; i++)
{
yield return new WaitForSeconds(0.02f);
float progress = (i + 1) / (float)10;
tarGet.transform.eulerAngles = Vector3.Slerp(A, B, progress);

}


I know it can use lerp to achieve this， but I need to know how this is done mathematically. like this

Vecctor3 C = B - A;
for (int i = 0; i < 10; i++)
{
yield return new WaitForSeconds(0.02f);
B += C/10;

}

• I would bet that Unity converts both orientations to quaternion, does the slerp, then converts the quaternion to euler angles again... Commented Sep 9, 2022 at 18:02
• Interpolating Euler angles is almost never what you want — instead of smoothly following the shortest path from one orientation to another, you can get chaotic-looking tumbling as shown in this answer. May I ask why you're reaching for Euler angles here? The code you've written looks like basically the answer — how does the behaviour of this code differ from what you want? Commented Sep 9, 2022 at 18:24

Yes you can:

So you have 2 vectors:

 Vector3 A = new Vector3(7,5,6);
Vector3 B = new Vector3(3,18,-46);


Now lets get those 10 intermediate vectors:

Vector3 C = B-A;
Vector3 d1 = (A+((C/10)*1)).normalized*A.magnitude;
Vector3 d2 = (A+((C/10)*2)).normalized*A.magnitude;
Vector3 d3 = (A+((C/10)*3)).normalized*A.magnitude;
Vector3 d4 = (A+((C/10)*4)).normalized*A.magnitude;
Vector3 d5 = (A+((C/10)*5)).normalized*A.magnitude;
Vector3 d6 = (A+((C/10)*6)).normalized*A.magnitude;
Vector3 d7 = (A+((C/10)*7)).normalized*A.magnitude;
Vector3 d8 = (A+((C/10)*8)).normalized*A.magnitude;
Vector3 d9 = (A+((C/10)*9)).normalized*A.magnitude;
Vector3 d10= (A+((C/10)*10)).normalized*A.magnitude;


now you can rotate A incrementally using something like this in your procedure:

A=d1;
yield return new WaitForSeconds(0.02f);
A=d2;
yield return new WaitForSeconds(0.02f);
A=d3;
yield return new WaitForSeconds(0.02f);
A=d4;
yield return new WaitForSeconds(0.02f);
A=d5;
yield return new WaitForSeconds(0.02f);
A=d6;
yield return new WaitForSeconds(0.02f);
A=d7;
yield return new WaitForSeconds(0.02f);
A=d8;
yield return new WaitForSeconds(0.02f);
A=d9;
yield return new WaitForSeconds(0.02f);
A=d10;
yield return new WaitForSeconds(0.02f);

• Have you heard about loops and arrays? Commented Sep 23, 2022 at 6:35
• have you considered that OP knows about loops (from his example)? All I wanted to show is how vectors can be manipulated without eular angles (exactly what OP asked in my opinion). I intentionally did not loop or array'ed anything to keep to the point. Commented Sep 25, 2022 at 19:49
• Also what does 'rotating a vector' even mean? - so I kept things simple Commented Sep 25, 2022 at 19:56