|
| 17 Apr 2017 01:51 AM |
Here's a tutorial on how to see if a part in Workspace is visible to an A## ### not going to write the actual script, so just use this guide and script it yourself.
1) Have the character and the head defined. Keep in mind that hats can block the view, so this might not work on AIs with shades, masks, or any hats covering the front of the head. If this happens, define the hat instead of the head, so it checks based from the hat.
2) Check if there's nothing in the way between the head and the part using a raycast. Raycasts are rays cast from a start point to an end point. They only stop at either the target, the range maximum, or if something gets in the way.
If the hit is the part targetted, then there is nothing in the way.
3) Check if its the field of view. It sounded complicated at first, but there's a simple way to do it. First, define the CFrame 4 studs in front of the head. Then, define the CFrame 4 studs in front the pointer CFrame, which is the CFrame that is positioned at the head, but facing the target. Then, check if the magnitude between the points is less than 5.
The way this works is that there will be two locations creating an angle. The first point of the angle is 4 studs in front of the head, and the second point is 4 studs from the head towards the target. If the magnitude is more than 5, then the angle created by the parts is too big. If the magnitude is less than 5, then the angle is small enough, and is indeed visible to the head. You can always change 5 to something else, if its not accurate.
4) Return the value. If there is nothing in the way AND its in the right angle, then the part IS visible, otherwise, its not.
|
|
|
| Report Abuse |
|
| |
Rice_Nice
|
  |
| Joined: 12 Mar 2017 |
| Total Posts: 166 |
|
|
| 29 Apr 2017 06:00 AM |
| Interesting that you check the length between the two vectors. Typically you would dot the two to find the angle between them, but I suppose it's not that much different. |
|
|
| Report Abuse |
|
| |
Rice_Nice
|
  |
| Joined: 12 Mar 2017 |
| Total Posts: 166 |
|
|
| 29 Apr 2017 07:48 AM |
| Yessir. I don't use my '09 anymore. |
|
|
| Report Abuse |
|