How can I get the distance of a player from a part without the Y axis?

I want to get the amount of studs between a player and a part, but ignoring the Y axis. Right now I’m using the DistanceFromCharacter method, but that includes the Y axis, and when I jump it changes the distance (which I don’t want to happen.) I think my question is pretty simple, so hopefully some people will be able to help me out.

The :DistanceFromCharacter method uses the Character’s head as a reference point of to find the distance of to another point. If you want to “ignore” the Y coordinate then create a Vector3 with the same Y coordinate as the head and pass that to DistanceFromCharacter.

DistanceFromCharacter(Vector3.new(Part.X, Head.Y, Part.Z))

4 Likes

I think you can also just kill the Y component:

local p1 = workspace.Part1.Position - Vector3.new(0, workspace.Part1.Position.Y, 0)
local p2 = workspace.Part2.Position - Vector3.new(0, workspace.Part2.Position.Y, 0)

print((p1 - p2).Magnitude, (workspace.Part1.Position - workspace.Part2.Position).Magnitude)

image

This got me an output of

  11.661903381348 13.114876747131
4 Likes

Thanks all, I understand how I can do this now.

1 Like