// Update is called once per frame
    void Update()
    {
        if (!paused)
        {
            closestSpider = FindClosestSpider();

            if (null != closestSpider)
            {
                closestSpiderController = closestSpider.GetComponent <RandomPathSpiderController>();

                //If there's a spider close to use that is turning (meaning it can't avoid us)
                //We should jump straight to the walk stage so that we can start to move out of the way
                if (closestSpiderController.currentWalkStage == WalkStage.Turn && currentMovementStage != MovementStage.WalkStage)
                {
                    GoToMovementStage(MovementStage.WalkStage);
                }
            }

            if (timeToLeaveWait != -1 && Time.time > timeToLeaveWait)
            {
                timeToLeaveWait = -1;
                //TODO check if we need to wait for a different spider
                SetWalkStage(WalkStage.Forward);
            }

            switch (currentMovementStage)
            {
            case MovementStage.RandomWait1:
                HandleRandomWaitStage();
                break;

            case MovementStage.TurnOnTheSpot:
                HandleTurnOnTheSpotStage();
                break;

            case MovementStage.RandomWait2:
                HandleRandomWaitStage();
                break;

            case MovementStage.WalkStage:
                HandleWalkStage();
                break;
            }
        }
    }
    //Compares the direction of our spider with the one passed in, the one pointing more towards the edge of the table has lower priority
    private bool DoesThisSpiderHavePriority(GameObject otherSpider)
    {
        RandomPathSpiderController otherController = otherSpider.GetComponent <RandomPathSpiderController>();

        if (otherController == null)
        {
            return(false);
        }

        bool thisSpiderHasPriority = false;

        if (transform.position.z > borderManager.UpBorderZ())
        {
            thisSpiderHasPriority = transform.forward.z < otherSpider.transform.forward.z;
        }
        else if (transform.position.z < borderManager.DownBorderZ())
        {
            thisSpiderHasPriority = transform.forward.z > otherSpider.transform.forward.z;
        }
        else if (transform.position.x > borderManager.RightBorderX())
        {
            thisSpiderHasPriority = transform.forward.x < otherSpider.transform.forward.x;
        }
        else if (transform.position.x < borderManager.LeftBorderX())
        {
            thisSpiderHasPriority = transform.forward.x > otherSpider.transform.forward.x;
        }

        //Switch the two priorities, only the spider with priority should be the one to do this, if they both execute the switch, we'll be back where we started
        if (thisSpiderHasPriority && (priority < otherController.priority))
        {
            int temp = priority;
            priority = otherController.priority;
            otherController.priority = temp;
        }

        return(thisSpiderHasPriority);
    }