Show a line of sight between two objects. Check if the line of sight is obstructed by the ArcGIS 3D object scene layer.
How to use the sample
- Open the LineOfSight scene.
- Click on the LineOfSightMap game object in the Hierarchy window.
- Set your API key in the Inspector window.
- Click play and see the line colors changes to red if there is any object obstructing the sight.
How it works
- Create an ArcGIS Map with the mesh colliders enabled.
- Attach an ArcGIS Camera component to the active camera.
- Create a parent game object with the ArcGIS Location component attached for other game objects to be nested under.
- Create a child game object as the moving target object under the parent game object with the ArcGIS Location component attached.
- Create a game object for the viewpoint and another for the line of sight under the game object with the ArcGIS Location component.
- Create a parent game object and nest the moving object's path points in the area.
- Attach a script to the parent game object that has the moving object's path points to update the Transform of the moving object according to the path points.
- Create a script to use Raycast.
- Use
Physics.Raycast
to check any any obstructions between the viewpoint and the moving object. - Use the
RaycastHit.point
property to determine where the line of sight intersects with the first object on its path. - If you have any objects that may interfere with the raycast check, use
Physics.IgnoreRaycastLayer
.
- Use
About the data
Building models for New York are loaded from a 3D object scene layer hosted by Esri.
Elevation data is loaded from the Terrain 3D elevation layer hosted by Esri.
Tags
line of sight, raycast, visibility, visibility analysis