Rotate object around origin

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

Hello,

I do not know how to rotate a object around the origin. A local rotation is no problem but the rotation around the origin does not work…
If it is possible I like to use Transform2D because it is available to all Nodes2D

Here is an example code:

extends Sprite

func _ready():
	var v = Transform2D()
	v = v.rotated(PI/2)
	v = v.translated( Vector2(100,0) )
	v[2] += Vector2(100,0) 
	self.transform = v

I like to rotate the sprite around Vector2(100,0) with a distance of Vector2(100,0)
I guess the solution is one line but I am not able to find it in the documentation…

:bust_in_silhouette: Reply From: Zylann
var point = Vector2(100, 0)

To place your node at a specific angle around a given point:

position = point + Vector2(cos(angle), sin(angle)) * distance

To make your node rotate around that point, while keeping the same distance:

position = point + (position - point).rotated(angle)

To make it look at the point:

look_at(point)