Open Sven-vh opened 11 months ago
For anyone that is looking for a RotateAround I made my own (2D) extension to it. It would still be nice if DoRotateAround could be implemented though!
public static class DOTweenExtensions {
public static Tweener DORotateAround2D(this Transform transform, Vector3 pivot, float angle, float duration) {
Vector3 startPos = transform.position;
float startAngle = Vector2.SignedAngle(Vector2.right, startPos - pivot);
float endAngle = startAngle + angle;
float startZRotation = transform.eulerAngles.z;
return DOTween.To(() => startAngle, x => startAngle = x, endAngle, duration)
.OnUpdate(() => {
float radian = startAngle * Mathf.Deg2Rad;
float radius = Vector2.Distance(pivot, startPos);
float x = pivot.x + radius * Mathf.Cos(radian);
float y = pivot.y + radius * Mathf.Sin(radian);
transform.position = new Vector3(x, y, transform.position.z);
transform.eulerAngles = new Vector3(0, 0, startZRotation + (startAngle - Vector2.SignedAngle(Vector2.right, startPos - pivot)));
});
}
}
Ahoy!
I indeed wanted to add it but my solution was similar to yours, using OnUpdate, which would create problems in case someone wanted to add a custom OnUpdate because it would overwrite it. I'm going to ponder this more though (and thanks for posting this)!
Why not just change the setter from x => startAngle = x
to x => {startAngle = x; //OnUpdate inner code}
?
Hi, I'm looking for a way to animate a transform that rotates around another transform. Exactly like the default Unity transform.RotateAround but in DOTween.
In 2015 you said it was on your todo list but I guess you never got around to it? Would love to have this!