What is the best way to get characters within a specific distance from specific point?

What is the best way to get characters within a specific distance…?
The basic way is that script gets parts of characters, then get distance of specific point and them.
But It has a big problem!
Imagine there’s a big part. Faces of the part are far away from its position.
I thought that I should use trigonometric function and inverse to get part’s vertex points then use Equations to check that character is in distance is whether true or false.
but it’s too hard.

image
oh god…
I scripted for 3 days.
But I couldn’t script the module correctly: get part’s vertex points.

I have thought this way is ALMOST IMPOSSIBLE. :frowning:

A new idea came into my mind;
It’s using Rays like this.
제목-없음-2
It has also a problem: it can’t find over walls.
But It’s ok in my game.
Because I want to get a character within a specific distance from a specific point and check if the character is not hidden in walls.
did you say Why didn’t you use it?
Because I don’t know if this is good for performance to the server or clients…

Do you have good ideas to get characters within a specific distance?

(If grammar is weird, I’m sorry because i’m South Korean XD)

This should be in #help-and-feedback:scripting-support

What you could do is check for all players what their distance is to the object with player using .Magnitude
(Magnitude on wiki)
Or you could check out Region3 to check if the player is in a certain region (I don’t know if it support a radius from a part, but you can check it out in this article

if parts are too big, using their distance can’t correctly check they are within the distance.

1 Like

You’re not exactly telling what the usage is of getting a specific distance. It is unclear what the result should be. Could you elaborate?


If you’re looking for player distance, use a function from the Player object. It is called :GetDistanceFromCharacter(), where the argument is the other position, a Vector3.

Then you’ve to put attachments for example on every corner of the big block and check the magnitude of every attachment, tho this won’t give you the perfect result.
It’s a solution to the current problem.

so i scripted to get part’s vertex point’s position using atan2 and cos and sin.
But It was too hard… :frowning:

That’s why CFrame was created :sweat_smile:, I am not an expert on CFrames, but I suggest doing extensive research on this. And using that to get the closest position inside the cube which is the closest to another point inside the part.
Other then that I am not sure how I could help if I am really being honest.
Good luck! :smiley:

Thank you, I didn’t think of using CFrame :smiley:

1 Like