#Retrieving global_position doesnt take into account position of the owner's parent node
18 messages · Page 1 of 1 (latest)
Did you set any of your transforms to top_level ?
Since overworld/exit_spawn are in the same canvas layer you could do something like (should work even if something inbetween is top-level etc.):
var exit_spawn_transform_relative_to_overworld: Transform2D = overworld.global_transform.affine_inverse() * exit_spawn.global_transform
Then relative position would be exit_spawn_transform_relative_to_overworld.origin.
Where do I set it to top_level?
Ok its on canvasitem.. lets see
No I dont have an active node with top_level set to true
Has overworld had its position changed
It should be at 0, 0 if you want to use global position
Topmost scene node should be 0, 0 too
NorthSea doesnt have 0, 0 (this is the node that is used to calculate the global position)
Overworld does have 0,0
Hmm not sure then honestly. Hope you find a solution, g2g for now
´ty. this is the ready function for north_sea node
If I put a node into from the NorthSea.tscn root to a child (e.g., fallahan_4), then the global_position stops working properly
which should be a regular node2d
more debugging: the moment I add the fallahan_4 node to provinces2, the global_position for northseatestspawn breaks here
if I make fallahan_4 local it starts working again (for northseatestspawn)
seems like a bugged implementation
Try adding such function:
func get_global_position_of(ci: CanvasItem) -> Vector2:
var t := Transform2D.IDENTITY
while ci:
t = ci.transform * t
if ci.top_level:
break
ci = ci.get_parent() as CanvasItem
return t.origin
And see if your_Node2D.global_position is indeed different than the result of get_global_position_of(your_Node2D).
If yes, then it's a bug. In such case updating to 4.2.2 will likely fix it.