user1485689
user1485689

Reputation: 35

RotateAround an object with using Quaternion

I have a great question for code masters. Think about you have only a calculated rotation value to rotate the transform. But you have to rotate around with its child pivot position. How do you solve this problem?

Thank you for your time :)

RotateAround an object with using Quaternion

Upvotes: 1

Views: 1677

Answers (2)

derHugo
derHugo

Reputation: 90833

Why reinvent the wheel? ;)

Unity has Transform.RotateAround and for the input you could simply use Quaternion.ToAngleAxis like e.g.

public static class TransformExtensions
{
    public static void RotateAround(this Transform transform, Transform pivot, Quaternion rotation)
    {  
        RotateAround (transform, pivot.transform.position, rotation);
    } 

    public static void RotateAround(this Transform transform, Vector3 pivotPoint, Quaternion rotation)
    {   
        rotation.ToAngleAxis(out var angle, out var axis);

        transform.RotateAround(pivotPoint, axis, angle);
    }
}

Upvotes: 1

user1485689
user1485689

Reputation: 35

I wrote the code. Here is the solution.

Solution

Upvotes: 1

Related Questions