+1 vote


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...

in Engine by (25 points)

1 Answer

+2 votes
Best answer
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:

by (28,835 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.