0 votes

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, distanceto doesn't seem to work, only gives 0 as an outcome.
here comes code
( for some reason get
position/ getglobalposition 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 :D

Godot version v3.2.3
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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

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

by (2,394 points)
selected by

Thank you, worked perfectly! :D

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.