0
\$\begingroup\$

In Vector math and translations we can do:

dir = (v1 - v2).norm

and then v1.translate(dir * 50) so v1 moves to the v2's direction.

What about rotation and eulerAngles?

Here's my attempt, but it doesn't work, probably from some obvious reasons.

Vector3 initial = ob1.transform.rotation.eulerAngles; // get it's initial rotation
ob1.Rotate(new Vector3(0,0,90)); // rotate
Vector3 after = ob1.transform.rotation.eulerAngles; // store new rotation
ob1.Rotate(new Vector3(0,0,-90)); // rotate back to initial

// here I need to calculate the direction so I can do rotate(dir * 50); or something similar

I need to get the rotation direction, so I can rotate the object continously with direction, not with a fixed desired angle value.

To be super clear, I need to get this blue line direction:

enter image description here

The object is initially rotated by (0,0,57). I need to rotate it around it's center (green axis).

I know I can do logo1.transform.RotateAround(logo1.transform.position, logo1.transform.up, 80); and it works, but I need the direction from this, so I can use it in Tweening.

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Here's a snippet of code that will do the trick:

Vector3 AxisBetween(Quaternion start, Quaternion end) {
    // Here we form a rotation that "undoes" the start orientation,
    // then applies the end orientation on top.
    Quaternion travel = end * Quaternion.Inverse(start);

    // By construction: end = (travel * start)
    // So travel serves as the "quaternion difference" between the two.

    // Now we just extract its axis of rotation.
    Vector3 axis;
    float angle;    
    travel.ToAngleAxis(out angle, out axis);

    // I can't recall what the range of these angles is, so this might not be required:
    if(angle < 0f)
        axis *= -1f;

    return axis;
}

Note that if start = end you'll get an axis full of infinities back, since a zero degree rotation around any & every axis maps start to end. ;) So be sure to check for infinities before using.

\$\endgroup\$

You must log in to answer this question.

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