Distance_to but only on x axies

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

Hi there!

I’ve been struggling with getting movement in 3d top-down to work, I want the “player” to follow the touch on the screen, I’ve tried a lot of things to get this to work to no avail.
But I had an idea and I don’t know if Godot even supported such a thing.
using distance_to I want to find how far away the curser is from my anchor, but it works as shown below

is most cases this is how you want it to work but in my case I don’t.
I want it to work more like it is shown below

if you can help me thank you so much!

does this help?

https://forum.godotengine.org/121204/calculate-the-x-axis-only

ramazan | 2022-06-19 10:45

:bust_in_silhouette: Reply From: bloqm

Perhaps I’m missing something, but:

distance = abs(position_A.x - position_B.x)

If that’s not what you want you can always call distance_to() with some extra steps:

var pos_a = Vector2(position_A.x , 0)
var pos_b = Vector2(position_B.x , 0)
distance = pos_a.distance_to(pos_b)