0

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

利维坦
  • 43
  • 7

1 Answers1

-1

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);
ShoulO
  • 499
  • 2
  • 6
  • Have you heard about loops and arrays? – Philipp Sep 23 '22 at 06: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. – ShoulO Sep 25 '22 at 19:49
  • Also what does 'rotating a vector' even mean? - so I kept things simple – ShoulO Sep 25 '22 at 19:56