Yes, but as you’ve found out, it’s vital to understand that the position, rotation, and scale of objects and components are “Local”. They are relative to the parent. If you have one object that is the child of another, it’s position will be an offset relative to its parent’s position. Likewise for rotation and scale. And these transformations stack up down the tree if you have “grandchildren”, “great-grandchildren”, etc. So only the top-level game objects that have no parent are in “Global” world coordinates.
The regular “go.get_position()”, “go.get_rotation()”, and “go.get_scale()” functions get the Local position/rotation/scale of the game object. There are other “go.” functions to get the Global world position, rotation, scale, or the full transform matrix of game objects if you need them. But keep in mind, there’s no “go.set_world_position”, you would have to use the world transform matrix to calculate the matching local position yourself. In other words, if you want to set the world position of an object (like putting it under the mouse cursor), don’t give it a parent that has any transform.
This sounds complicated, but it really is intuitive. Child objects are “physically” attached to their parent. A watch would be a “child” of your arm—It moves along with your arm no matter how your arm moves, but the watch’s “Local” position relative to your arm doesn’t change.
Almost right. “action.x” and “action.y” from input are in GUI/“Design” coordinates. “action.screen_x” and “action.screen_y” are screen coordinates.
There is a mistake in dapetcu’s original post. GUI positions are NOT in Screen coordinates. The are in the GUI/“Design” coordinate system (the same coordinates as action.x and action.y).
You can easily check this. Make a gui with a script and add it to your main collection. Add a box node and anchor it to the right side of the screen. Add this to the script:
function update(self, dt)
local node = gui.get_node("box")
local guiPos = gui.get_position(node)
local screenPos = gui.get_screen_position(node)
print("GUI pos = " .. tostring(guiPos) .. ", Screen pos = " .. tostring(screenPos))
end
At first when you run the game they will both be the same, but when you stretch the window horizontally, the GUI pos will stay the same and the Screen pos will change.
You can also try printing out action.x/y and action.screen_x/y in your input function to see how they change when you resize the window.