Local/global position, rotation around point

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

Basically, I’m trying to get a node’s position rotated around it’s parent, then draw a line from there to a position that isn’t important to this question. I see two ways to achieve this, both of which I have no idea how to do:

  1. Use the Vector2.rotated() method on the local position and then translate it into global position.
  2. Rotate the global position relative to the parent node’s global position.

It doesn’t really matter which way I use, help with either one is appreciated. Thanks!

Any chance of providing an illustration of the important points here? For some reason, I can’t quite wrap my head around your description…

jgodfrey | 2020-11-26 02:25

Sorry, my problem is kinda hard to explain without going on a huge tangent. I have a node with a Position2D inside of it. I want the Position2D’s global position rotated relative to the parent node, so that it points towards the mouse position. I hope this helps :confused:

Afely | 2020-11-26 02:53

:bust_in_silhouette: Reply From: jgodfrey

Why not simply parent the item you want to rotate to a node that’s aligned with the parent you want to rotate around. With that, you could simply rotate that parent node as needed.

So, if you have something like this:

    Position2D (you want to rotate this around Parent, without rotating Parent itself)

You could do this (for example):

    Node2D (position this at the same location as Parent)
        Position2D (the node to rotate)

Now, to rotate Position2D around Parent, just rotate Node2D as necessary