Im new to Godot and game programming.
How do I get an objects location to be turned into a var

  • duane replied to this.
  • The_Grass_man

    Objects that are made from the Control class, like buttons, panels, and rectangles, have a rect_position property that gives a Vector2 with the x and y value of the control. Objects that are made from Node2D, like sprites and tilemaps, have a position property that does the same. So if you have a script on the object, you just have to assign the property to a variable.

    var pos = rect_position

    If you want the position in another script, you could refer to it with

    var pos = $my_object.position

    You can see this in the first game tutorial in the documentation.

    The_Grass_man

    Objects that are made from the Control class, like buttons, panels, and rectangles, have a rect_position property that gives a Vector2 with the x and y value of the control. Objects that are made from Node2D, like sprites and tilemaps, have a position property that does the same. So if you have a script on the object, you just have to assign the property to a variable.

    var pos = rect_position

    If you want the position in another script, you could refer to it with

    var pos = $my_object.position

    You can see this in the first game tutorial in the documentation.

      duane Thank you but I should have put down I meant in 3d will this work in 3d too