generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Get a table of all the parts a player is looking at

Previous Thread :: Next Thread 
AstroCode is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. SpeedZero
Joined: 17 Aug 2013
Total Posts: 59
12 Sep 2015 11:02 PM
instawin you smart thing you
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Sep 2015 11:02 PM
eww I'd just Region3
Report Abuse
lego555444 is not online. lego555444
Joined: 21 Sep 2008
Total Posts: 1383
12 Sep 2015 11:04 PM
Region3? Nah? Have fun doing that with a rotation
Report Abuse
cntkillme is not online. 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
lego555444 is not online. lego555444
Joined: 21 Sep 2008
Total Posts: 1383
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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Sep 2015 11:17 PM
noty, that's not gonna be more efficient.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
13 Sep 2015 12:28 AM
Regions are limited to 100 parts. They're not a good solution.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
13 Sep 2015 12:34 AM
Oh yeah that limit.
Report Abuse
AstroCode is not online. 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 is not online. 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 is not online. 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 is not online. 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
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
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 is not online. 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
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
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 is not online. 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
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
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 is not online. AstroCode
Joined: 09 Oct 2009
Total Posts: 1122
13 Sep 2015 12:57 PM
:( Alright, thanks.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image