Hi, this seems like a simple thing but I can't find any information about it. I wanna know if there's a way to change the "origin" of a node that Godot uses for positioning. More specifically I want to center it.

Meaning, if I have for example a TextureRect and I put it at coordinates 0;0, I want the centre of the texture to be at 0;0, not the top left of it.

Right now when I'm changing the node's position, I have to calculate the center from its width and height and then offset the position accordingly. Being able to change the origin would make it a lot easier.

P.S.: I'm saying "origin" because that's what it's called in Blender :-) I don't know if Godot has a term for it.

  • housatic Parent it to another node and move that parent node. It will effectively act as a pivot.

DaveTheCoder Unless I'm doing something wrong it seems that PivotOffset doesn't affect position, I'm guessing it's just for rotation and scale like the docs say. Oh well, I guess I'll keep calculating the offsets myself. Thanks for the suggestion.

TextureRect test = new TextureRect {Texture = ...};
test.PivotOffset = test.Size/2;
  • xyz replied to this.

    housatic Parent it to another node and move that parent node. It will effectively act as a pivot.

      xyz Like this?

      Node2D test = new Node2D();
      TextureRect tex = new TextureRect {Texture = ...};
      tex.Position = new Vector2(-tex.Texture.GetWidth()/2, -tex.Texture.GetHeight()/2);
      test.AddChild(tex);

      It's more complicated than I hoped for, but it does work :-)

      • xyz replied to this.

        housatic It's more complicated than I hoped for, but it does work :-)

        You can make a helper function that does this and call it whenever you need to set it up 😉