Intro

In A2, a path network will be generated by creating valid edges (PathEdges) connecting nodes (PathNodes), such that the AI agent can navigate between any path node without colliding with an obstacle or canvas/world boundary.

description

Resources

Tips

  • Scene 7 is most useful for debugging

Overview

Set up

  • Select Scenes/PathNetwork to open the scene

  • Click play

    • Clicking will highlight the nearest node that has a line of sight with the mouse click
  • The objective is to figure out how to connect the nodes, ensuring that none of the edges are too close to anything that would prevent the agent from traversing along the edge

description

Reference Implmentation

Scenes

Scene 1

Scene 1

Scene 1

Scene 2

Scene 2

Scene 2

Scene 3

Scene 3

Scene 3

Scene 4

Scene 4

Scene 4

Scene 5

Scene 5

Scene 5

Scene 6

Scene 6

Scene 6

Scene 7

Scene 7

Scene 7

Unit/Integration Testing

Shared Tests

castro

PathNetwork

PathNetwork class:

  • Collects path nodes and builds edges between them
  • Calls CreatePathNetwork.Create()
  • Stores the graph and it in Unity
  • Modified version also displays nodes indices

Display indices over nodes

description

CreatePathNetwork

  • In CreatePathNetwork.cs, implement CreatePathNetwork.Create() in order to generate a path network from pathNodes.

Fully connected network

public static void Create(Vector2 canvasOrigin, float canvasWidth, float canvasHeight,
    List<Polygon> obstacles, float agentRadius, float minPoVDist, float maxPoVDist, ref List<Vector2> pathNodes, out List<List<int>> pathEdges,
    PathNetworkMode pathNetworkMode)
{
    Debug.Log($"{pathNodes.Count} nodes");
    pathEdges = new List<List<int>>(pathNodes.Count);
    Debug.Log($"Capacity: {pathEdges.Capacity}");
 
    for (int i = 0; i < pathNodes.Count; ++i)
    {
        pathEdges.Add(new List<int>());
        Debug.Log("PathNode " + i + ": " + pathNodes[i]);
    }
 
    for (int y = 0; y < pathEdges.Count; y++) {
        for (int z = 0; z < pathNodes.Count; z++)
        {
            if (y != z)
            {
                pathEdges[y].Add(z);
            }  
        }
        Debug.Log("PathEdge " + y + ": " + string.Join(", ", pathEdges[y]));
    }
}
 
description

Boundary Conditions

Make sure any edge in the path network is traversable by an agent that has physical size. That is, edges in the path network should never come too close to any Obstacle such that an agent blindly following the path edge collides with an Obstacle (or the edges of the map).

TODO

  • No self edges
  • No duplicate edges
  • Minimum distance between nodes of an edge and canvas edge > agentRadius
  • Minimum distance between nodes of an edge and obstacle edges > agentRadius
  • Minimum distance from path edge to obstacle vertices > agentRadius

Helper Methods

Tip

In terms of Computational Geometry, the DistanceToLineSegment() works best with floats. You can use the poly.getPoints(), which are unscaled floats. The poly.getIntegerPoints() are the equivalent vectors in scaled integer form (by 1000)