# Child node in fixed position while parent is moving

Godot 4.2.2

### Question

Hi everyone!

I have a local coordinates issue that maybe you can help me to solve. I think I’m very close to solve it, but something is failing…

so, we have three nodes: one parent with two children.

Node A
|- Node Current
|- Node Target

Node Target has always the same local position from to the parent (Node A). This never changes.
Also, Node A is moving in the world, changing his position constantly and therefore Node Target moving along with Node A.
But, I want the Node Current to stay in specific position in the world ignoring Node A’s position.

As you can imagine, the problem is with the position of the Node Current… because it’s a child of Node A, this one is carrying him on.

What I want to achieve is, after specific distance from Node Current to Node Target, set the position of the Node Current same as Node Target.
After that, the Node A keeps moving (along with Node Target), but I want to Node Current to stay exactly in the same place where it was positioned in the previous step regardless of Node A position.
Then, we repeat the process: after some distance between Node Current and Target, we move again the Current to position of Target and so on…

I solved this using GlobalPositions, but… I cannot use globals because later Node A is child of another nodes that are moving as well, so Node Current position is the sum of all global position of Node A and his parents and gets crazy.
I want the solution to be local regardless of what’s going on the global node tree.

Any idea about how to solve this?

I tried the following, but it doesn’t work because sometimes Node A rotates into a different position and the Node Current get deviated depending or where Node A is heading:

``````var distance = NodeTarget.Position.DistanceTo(NodeCurrent - Position);
if (distance > maxDistance)
NodeCurrent = NodeTarget.Position + Position;

MeshInstaceVisualDebug.Position = NodeCurrent - Position;
``````

This is the script in Node A, so Position is the position of Node A.

You can set the NodeCurrent `top_level = true`, this will ignore any parent transform

Is there a way for 2D nodes? There doesn’t seem to be a top level option for them.

Top Level exists for Control, Node2D (CanvasItem), and Node3D

Oh, whoops… thanks anyway