Exemplo n.º 1
0
    protected void HandleMoving()
    {
        if (currentPath == null)
        {
            return; //no movement
        }

        //Move toward the next cell if not reached
        if (targetCell != null && Vector3.Distance(transform.position, targetCell.CenterWorld) > 0.001f)
        {
            isMoving = true;
            MoveToward(targetCell.CenterWorld);

            Vector3 dir = (targetCell.CenterWorld - previousCellPos).normalized;
            RotateToward(transform.position + dir);
        }
        //Select the next cell to go if there's still some path to go
        else if (currentPath.HasNext())
        {
            previousCellPos = transform.position;
            targetCell      = currentPath.Next();
        }
        //Stop the movement if it's over
        else
        {
            //The path is finished, we stop moving.
            StopMovement();
        }
    }