ArgumentOutOfRangeException; Unsure how to fix

  • A* version: 4.2.17, free version
  • Unity version: 6000.1.12f1

I have a custom movement script using the pathfinding system that I made following the tutorial, but I tried using rigidbody2D forces instead of transform because I wanted the motion to be more fluid. However, this has led it to hit walls and cause an out-of-range exception for a reason I probably wouldn’t understand. I tried looking for help with this issue but all the fixes are in the paid versions, which I’m not in a position to get right now. Could someone help me either fix this issue or make the agent less likely to bump into so many walls?

EDIT: Just realised, I should probably share the portion of my code containing this error.

void TrackPlayer()

{

    if (path != null)

    {

        reachedEndOfPath = false;

        while (true)

        {

            float distanceToWaypoint = Vector2.Distance(transform.position, path.vectorPath\[currentWaypoint\]);  // This line is causing my error

            if (distanceToWaypoint < nextWaypointDistance)

            {

                if (currentWaypoint + 2 < path.vectorPath.Count)

                {

                    currentWaypoint++;

                }

                else

                {

                    reachedEndOfPath = true;

                    break;

                }

            }

            else

            {

                break;

            } 

        }

    }

    Vector2 dir = (path.vectorPath\[currentWaypoint\] - transform.position).normalized;

    Vector2 force = flightStrength \* dir \* 1.1f - rb.linearVelocity \* 0.1f;

    rb.AddForce(force);

}

If any extra context is needed, please tell me and I will put it in the replies or make an edit.