FPS Tutorial Waypoints question

I'm following the FPS tutorial (from unity) to create a Waypoints system.

I've created the waypoint system and it works fine. My problem is that I need to reduce the distance so that each waypoint only connects to the closest waypoint and not to all waypoints around.

I found out that I can control which waypoints are connected with this:

public var kLineOfSightCapsuleRadius = 2.0;

function RecalculateConnectedWaypoints ()
{
    connected = Array();

    for (var other : AutoWayPoint in waypoints) {
        // Don't connect to ourselves
        if (other == this)
            continue;

        // Do we have a clear line of sight?
        if (!Physics.CheckCapsule(transform.position, other.transform.position, kLineOfSightCapsuleRadius)) {
            connected.Add(other);
        }
    }   
}

But I don't understand how the CheckCapsule works.

Thanks

You should check the documentation as it spells out what it does rather well. Or is there any part of the description that is unclear?

Update: Your confusion is not only on what CheckCapsule does, but how it's being used. It's used solely to check that there are no obstacles between transform.position and other other.transform.position in a tube of radius kLineOfSightCapsuleRadius. Reducing that value would only reduce the width of the tube that's checked for possible collisions. It does not by itself limit the connections to the shorter waypoint.

If you wish to do that, you should update the code yourself to:

  1. Check the distance between your waypoint and the one being evaluated.
  2. If smaller than the last smaller one found, save it.
  3. If not, move on to the next.

Once you're done with all waypoints, simply connect to the one found to have the shortest distance.

I added this line of code and it seems to be working now:

if (!Physics.CheckCapsule(transform.position, other.transform.position, kLineOfSightCapsuleRadius)) {

            var distance = Vector3.Distance(transform.position, other.transform.position);

            if(distance < 2.1)
            {
                connected.Add(other);
            }
        }

Thanks Ricardo