Difference between the terms "global/local space" and "global/local frame"

Godot Version

godot-4 (I think the same thing applies to other versions too.)

Question

I’ve been reading about Node2D and Transform2D from the docs and I found some confusing terms (at least for me).

I understood that transform, and all the other Node2D properties without the global_ suffix are relative to the node’s parent. I think calling transform as local_transform wouldn’t change the meaning, and I’m familiar with the concept of objects in global coordinates or local coordinates. my understanding of the word “local” is “local = relative to a parent”. the terms “global coordinate space” and “local coordinate space” are both used in the Node2D page (here).

Now, I played around with some methods of Transform2D and I didn’t quite understand the description “global/parent frame” in the rotated() method, and “local frame” in the rotated_local() method. I found that,

  • global frame behaved like global space
  • parent frame behaved like local space
  • local frame seems to refer to the coordinate system whose origin is on the center of the node

Mainly, I’m confused why there are similar terms “space” and “frame”, but they behave differently. Can someone help?

As you have correctly identified, global space is relative to the ‘world’, while local space is relative to the parent. You can think of it as the coordinate systems from the perspective of the node. When you set the position or the rotation you simply overwrite these values in the nodes transform. When you are developing in Godot, you are usually thinking in terms of these spaces.

‘Frames’ on the on the other hand you can think of as the perspective of the transform - if this makes sense :stuck_out_tongue: . When working with transform matrices, you can think of each operation updating the coordinate system. The original coordinate system, before transforms are applied, is the global/parent frame, while the coordinate system after the operation is the local frame.
E.g., let’s say you have a node that is moved (translated) 10px to the right. This means after the translate, the local frame’s origin is at (10, 0). If you use rotated_local, the node will rotate around that new local origin - as if it’s rotating in place at (10, 0).
If you use rotated it will be rotated before being moved. This means the moving is happening in this new rotated coordinate system, i.e., it will move in the direction of the rotation. Alternatively, you can also see it as rotating around the parent origin (as you have mentioned).

Mathematically, when applying the rotation relative to the local frame you apply the existing transform to the rotation matrix (X * R) and vice versa for the parent frame (R * X). You can read more about matrices and transforms here: Matrices and transforms — Godot Engine (stable) documentation in English

I hope this helps.

1 Like