Reputation: 35
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 :)
Upvotes: 1
Views: 1677
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