Is there any equivalent, in GDScript, to the RotateAround() method?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By IndigoGames

There is ,in unity engine, a method called RotateAround() wich allows you to rotate a game object around a world point. My question is: is there a similar method in GDScript?
I’ve done some reserch and I haven’t come to any conclusive results.

:bust_in_silhouette: Reply From: Zylann

I don’t think it exists, but it’s a shorthand so it can be written from existing functions.
You can try this:

func rotate_around(point, axis, angle):
	# Get transform
	var trans = transform

	# Rotate its basis
	var rotated_basis = trans.basis.rotated(axis, angle)

	# Rotate its origin
	var rotated_origin = point + (trans.origin - point).rotated(axis, angle)

	# Set the result back
	transform = Transform(rotated_basis, rotated_origin)

Note: if you want it to work in global space regardless of parenting, use global_transform instead of transform.