Need to calculate the distance

Good afternoon, help. Need to calculate the distance between Area2D and CharacterBody2D. Func distance_to() does not work

That is the correct way to check the distance, show what is going wrong and some code would help understand what you’re doing wrong

1 Like

This code is bound to an Area2D object, I think then replace the parent node with Node2D and the problem will be solved - 2024 05 08 06 56 17 — Postimages. Sorry, I don’t know how to attach a screenshot)

From the screenshoot you posted I see that you are passing the node, but not a Vector2, just pass the local position (or global_position) like this:

distance = position.distance_to(weapon_parent.position)

I’m assuming here that you are calculating the distance from the CharacterBody2d, if you need to do it from other script you just need a reference to the two nodes and use position or global_position.

1 Like

Thank you so much :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.