Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Getting parts in view on a player's screen?

Asked by
Axstin 55
10 years ago

How would I go about getting all the parts that is within view of a players screen?

Thanks.

0
Anyone? Axstin 55 — 10y
0
Easier said than done. I'm interested to know if anyone has a solution to this using Region3 (even with some inaccuracy because of the lack of rotated Region3s). Currently, the only method I can think of is gathering all the BasePart descendants of Workspace, and then checking individually against a function that transforms the 3D coordinates to 2D counter-parts. I have a function to do that if yo MrNicNac 855 — 10y
0
Yea, I was thinking about using Region3, but then I remembered you can't rotate Region3 areas. Also, did you mean to answer or post a comment? Your post was cut off :P Axstin 55 — 10y

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Sorry for a year(!)'s delay, but ROBLOX just released a Camera update:

local pos, vis = workspace.CurrentCamera:WorldToScreenPoint(workspace.Part.Position)

if vis then
    print("Point is Visible on screen!")
end

You can use this to loop through every part you care about to see if it's Visible. On it's own, this isn't perfect, but it's a good start.

Ad
Log in to vote
0
Answered by 10 years ago

Not quite sure on how the FieldOfView property works for Camera's, but couldn't you cast a bunch of ray's within a (FieldOfView?) degree radius to try and find every part? After all, even if you could get Region3 to work or something like MrNicNac suggested, you would end up with parts that were hidden behind walls as well. The only way to counter that is to use raycasting. But if that's fine, then you can try this...

1) Get every BasePart in workspace 2) Use (http://pastebin.com/54QJiii6) in order to get the closest point on a part from your camera's position 3) Compare the unit vector of your camera and the unit vector from your camera to the point on the part. If it is within # degrees/distance of each other, then at least some section of it is on the screen

Answer this question