alij12
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 1204 |
|
|
| 20 Aug 2016 07:47 PM |
| Is it possible to know if a player can see something? As in, its within view of their camera? |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 07:48 PM |
| you can use region3 from the cameras min ScreenPoint to the max ScreenPoint by using the function in the camera at 0,0 pixels and at the viewport size |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 07:49 PM |
and multiplying by lookvector.
OR,
you can check if the camera is facing something by seeing how far the direction is off from the center of the screen |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 20 Aug 2016 07:50 PM |
those are dumb ways.
http://wiki.roblox.com/index.php?title=API:Class/Camera/WorldToScreenPoint returns a boolean if the obj is visible in camera
|
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 20 Aug 2016 07:51 PM |
Two ways to check.
1. Use Camera.WorldToScreenPoint(object.Position). If it's a value located on the screen, then they can see it.
2. Obtain a unit vector at the position of the camera pointing towards the object. Take the dot product of that vector and the camera's lookVector. Take the inverse cosine of the result to obtain the angle between the two vectors, and check if that's less than the camera's field of view.
Pretty sure #2 would be more efficient, despite the explanation being longer.
|
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 07:52 PM |
| oh ok i didnt know about the second argument worldtoscreen returns lol oops |
|
|
| Report Abuse |
|
|