Wrong movement from 0 to 5 with a -2 wanted (from 0 to 6)

Hi,

I don’t why my red cursor goes from 0 to 5 waypoints ? I wanted him to go from 0 to 6 waypoints because I choose a movement of -2 in my game. Can someone help me please ?

 if (movement != 0)
            {
                Vector2 posInit = wayPoints[currentIndex].position;
                int wantedIndex = 0;
                if (wayPoints.Count > 0)
                {
                   wantedIndex = ((currentIndex + movement) % (wayPoints.Count - 1) + (wayPoints.Count - 1)) % (wayPoints.Count - 1);
                }
    
    
                Vector2 posEnd = wayPoints[wantedIndex].position;

Strikes me an easier way to calculate your target is:

    wantedIndex = currentIndex + movement;
    If (wantedIndex < 0)
    {
    wantedIndex += wayPoints.Count
}

Thanks for the solution :slight_smile: