Topic was automatically imported from the old Question2Answer platform.
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.
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.