AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
|
| 12 Sep 2015 09:39 PM |
| How would I get a table of all the parts on a player's screen? I know this uses raycasting, but I really have no idea how. |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 12 Sep 2015 10:46 PM |
FindPartOnRay() will return the first part that intersects a Ray and the position at which it does, but you'd have to call it so many times that it wouldn't be a feasible way to do it.
If you draw a Region3 from the character's head to an arbitrary vanishing point, you could get an area representing something like a field of view(could be accurate if the camera's FieldOfView is 45 and the vanishing point is at least twice the distance of the farthest part in the field of view), so that you could use FindPartsInRegion3WithIgnoreList() to get up to 100 parts.
Other than defining your own region and finding all the parts, in workspace, within it(the most effective of these), that's all I can think of. |
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 12 Sep 2015 10:56 PM |
http://wiki.roblox.com/index.php?title=API:Class/Camera/WorldToScreenPoint
|
|
|
| Report Abuse |
|
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 12 Sep 2015 10:57 PM |
| i'd loop through all the parts in workspace locally and detect if the part is visible to the player's camera with that method |
|
|
| Report Abuse |
|
|
SpeedZero
|
  |
| Joined: 17 Aug 2013 |
| Total Posts: 59 |
|
|
| 12 Sep 2015 11:02 PM |
| instawin you smart thing you |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 12 Sep 2015 11:04 PM |
| Region3? Nah? Have fun doing that with a rotation |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Sep 2015 11:13 PM |
| I'd rather have a little bit of inaccuracy and a lot more efficiency than a lot less efficiency. |
|
|
| Report Abuse |
|
|
|
| 12 Sep 2015 11:15 PM |
| You want efficiency? Fire an explosion with a radius that matches your field of view straight out of your look direction and grab all the parts it hits |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Sep 2015 11:17 PM |
| noty, that's not gonna be more efficient. |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 12:28 AM |
| Regions are limited to 100 parts. They're not a good solution. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
|
| 13 Sep 2015 07:52 AM |
I can't use Region3 and I can't use raycasting, so do I have any other options?
I'm using this in a building game that could potentially have tens of thousands of parts. I don't want to iterate through all of workspace each time I do this. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 13 Sep 2015 07:56 AM |
What about this? http://wiki.roblox.com/index.php?title=API:Class/Camera/ScreenPointToRay
"You're all idiots" |
|
|
| Report Abuse |
|
|
AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
|
| 13 Sep 2015 08:20 AM |
| @rayk I was fiddling around with ScreenPointToRay last night, but rays only return the first part they hit. |
|
|
| Report Abuse |
|
|
AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
|
| 13 Sep 2015 09:01 AM |
| Does anybody know when the studio tools are going to be open-sourced? When they are, I could look through those. Until then, does anybody have any ideas? |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 10:35 AM |
What studio tools exhibit the behavior you're looking for?
As for the solution to your problem, what you'd need to do is recurse through all parts in the workspace, covert their edges to 2D lines (convert each vertex to a 2D point with camera:WorldToScreenPoint(v3) (http://wiki.roblox.com/index.php?title=API:Class/Camera/WorldToScreenPoint) and then check if the line between those points intersects the screen. If any one of them do, it's on-screen. If none of them do, it's not on-screen. Don't make the mistake of using the second returned value of WorldToScreenPoint for checking if a point is on-screen or not. All vertices can be off-screen while the part is still on-screen (i.e. you're really zoomed in on a part and can only see one face but not its vertices) |
|
|
| Report Abuse |
|
|
AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
|
| 13 Sep 2015 11:03 AM |
| @Echo The Studio tool I'm talking about is the Select tool. You can click and drag to draw a box on your screen and select all the parts inside the box. I've already made my own, I just want it to be more efficient. |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 11:45 AM |
| Oh, all that does is select parts whose center are within that box. You don't need to do any fancy intersect detection for that. All you need to do is convert the model/part's center to screenspace and then check if that point is within your selection box. |
|
|
| Report Abuse |
|
|
AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
|
| 13 Sep 2015 12:23 PM |
| @Echo Right, so I'm trying to iterate through less parts by getting a table of all the parts the player is looking at, rather than iterating through all the parts in workspace. |
|
|
| Report Abuse |
|
|
|
| 13 Sep 2015 12:42 PM |
| You can't get the parts a player is looking at without iterating through all the parts in the workspace. |
|
|
| Report Abuse |
|
|
AstroCode
|
  |
| Joined: 09 Oct 2009 |
| Total Posts: 1122 |
|
| |
|