No problem, glad to help.
Firstly, I just fixed a mistake in my answer where I wrote global_transform.origin()
when it was supposed to be global_transform.origin
.
There is a more direct way of doing that in 2D, which is to use the global_position
property.
So you could try running this code in your player script.
var hook = get_node("../Grapple_hook")
var player_position = global_position
var hook_position = hook.global_position
var d = player_position.distance_to(hook_position)
I think the errors you are getting are because there was a mistake when using get_node
, since it says on base: 'Nil'
. You can test whether you got the node by running print(hook.name)
.
Feel free to ask more questions and I will gladly help.