How to get the distance between player and target object? (2D)

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

Hello!

So after a good half a year of break I’m trying to get back to Godot, so my knowledge -at its best - is relatively unreliable.
My aim is to measure up the distance between the player (KinematicBody2D) and a target (Area2D) - the concept is that when the player gets closer to the hidden object, it changes shape indicating that yay, we are getting closer.

My main problem is that while I can get both the position of the KinematicBody2D and the target, distance_to doesn’t seem to work, only gives 0 as an outcome.


( for some reason get_position/ get_global_position doesnt even show up as an option let alone work)
enter image description here
I’d appreciate any kind of help or suggestions!
Have a great day all :smiley:

:bust_in_silhouette: Reply From: Inces

It should work, You propably overcomplicated something with these postargets pospositions posplayers :slight_smile:

Anyway You can try measure lenght() of positions difference. (target.position - player.position).length(). But make sure You adress them correctly and use global positions

Thank you, worked perfectly! :smiley:

PrivateCoppery | 2021-10-12 14:55