Any way to get a part's position In a certain range?

Basically, my goal is to get all the players in view of a player. To do this, I was hoping to create some sort of function that if the player had to turn a certain amount to face them, they would be added to the table. Kind of like this…

My method

When I say x I’m referring to the distance sideways relative to the LookVector
When I say z I’m referring to the imaginary line parallel to the LookVector
Like this:

The method I’d thought of was trial and error until I found the right ratio of Z and X to replicate the field of view 1z = 3x etc so I could have a ratio of how much the fov opens up as you’d stare forward. From there I would subtract the owner’s Z from the target’s Z.

Now remember that ratio we talked about? I would take that new TargetZ-OwnerZ and divide it by the ratio I came up with. If (OwnerZToTheTarget/TargetX-OwnerX) < Ratio then that part would be counted. Otherwise it would be ignored.

Where it fails:
CFraming really isnt my strong suit whatsoever, so I have no idea how to get the points I described, and I’m not sure if OwnerZToTheTarget is possible to get. If you could help bring this method to life, or at least push me in the right direction, I’d appreciate that.


I can try my best to re-explain this method if you’d like to build on it.

I’m not asking for code but just what function/method I could use to achieve this? I would also appreciate a link to the wiki detailing how to use these kinda of methods in the future.

1 Like

There’s WorldToScreenPoint. It returns two things, the second is a boolean (true/false) that indicates whether or not the point you’re checking is on-screen.

3 Likes

How would I use this? It returns tuple, so does that mean I would have to use a comma in the variable?
Example:

local Offset,OnScreen = cam:WorldToScreenPoint(PlayerTorsoPosition)
If OnScreen then
--etc.
end

Edit: I closed studio before making this post, so I was just making sure. Didnt want to waste a reply to say this

Yep! That’s how you’d use it.

(You could have tested this yourself before asking, btw.)

3 Likes