#Retrieving global_position doesnt take into account position of the owner's parent node

18 messages · Page 1 of 1 (latest)

sleek spruce
#

Im querying global_position for exit_spawn. This returns the global position with respect to the north_sea node. I need this for overworld. any pointers to fix this here? I checked all scripts and they extend from Node2D..

harsh shore
paper minnow
sleek spruce
#

Ok its on canvasitem.. lets see

#

No I dont have an active node with top_level set to true

kindred wedge
#

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

sleek spruce
#

NorthSea doesnt have 0, 0 (this is the node that is used to calculate the global position)
Overworld does have 0,0

kindred wedge
#

Hmm not sure then honestly. Hope you find a solution, g2g for now

sleek spruce
#

´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

sleek spruce
#

more debugging: the moment I add the fallahan_4 node to provinces2, the global_position for northseatestspawn breaks here

sleek spruce
#

if I make fallahan_4 local it starts working again (for northseatestspawn)

#

seems like a bugged implementation

paper minnow
#

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.