Determine the visibility for a line of sight

Show a line of sight between two objects. Check if the line of sight is obstructed by the ArcGIS 3D object scene layer.

Image of line of sight

How to use the sample

  1. Open the LineOfSight scene.
  2. Click on the LineOfSightMap game object in the Hierarchy window.
  3. Set your API key in the Inspector window.
  4. Click play and see the line colors changes to red if there is any object obstructing the sight.

How it works

  1. Create an ArcGIS Map with the mesh colliders enabled.
  2. Attach an ArcGIS Camera component to the active camera.
  3. Create a parent game object with the ArcGIS Location component attached for other game objects to be nested under.
  4. Create a child game object as the moving target object under the parent game object with the ArcGIS Location component attached.
  5. Create a game object for the viewpoint and another for the line of sight under the game object with the ArcGIS Location component.
  6. Create a parent game object and nest the moving object's path points in the area.
  7. 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.
  8. 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.

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

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.