Is there a way to get convert a global position to a local position for a control node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By db0

I find myself in a position where I want to convert a global viewport position, to the position within a control node. I discovered that a node2d provides a method to_local (Node2D — Godot Engine (stable) documentation in English) but that method does not seem to exist for control nodes. Is there another way

:bust_in_silhouette: Reply From: db0

I figured out a workaround. I added a child Node2D node into my control node and I call the to_local() from there and it works!

:bust_in_silhouette: Reply From: wonson

For people using Control node, you can get global position.

because local position is the position relative to self as (0, 0)

So in fact,
localPositionOfAInB = globalPositionA - globalPositionB