Пример #1
0
    public StepNode(Tile _tile, Tile _target, DistMethod method = DistMethod.GRID)
    {
        DrawLines    += DrawLine;
        DestroyLines += DestroyLine;
        tile          = _tile;

        if (method == DistMethod.GRID)
        {
            //Full Grid 450
            float xDiff    = Mathf.Abs(_tile.X - _target.X);
            int   yDiff    = Mathf.Abs(_tile.Y - _target.Y);
            float straight = Mathf.Abs(xDiff - yDiff);
            float diag     = Mathf.Max(xDiff, yDiff) - straight;
            crowDist = straight + diag * 1.414f;
        }

        if (method == DistMethod.MANHATTEN)
        {
            // Manhatten - 800
            crowDist = Math.Abs(_tile.X - _target.X) + Math.Abs(_tile.Y - _target.Y);
        }

        if (method == DistMethod.VECTOR_3)
        {
            //Naive - Unrelated - 1200
            crowDist = Vector3.Distance(_tile.transform.position, _target.transform.position);
        }
        DrawLine();
    }
Пример #2
0
 void Start()
 {
     currentMethod = distanceMethod;
     Pathfind();
     startingObj.SetPathfinder(Pathfind);
     targetObj.SetPathfinder(Pathfind);
 }
Пример #3
0
 void Update()
 {
     if (isPathfinding)
     {
         PathfindLoop();
     }
     if (currentMethod != distanceMethod)
     {
         currentMethod = distanceMethod;
         Pathfind();
     }
 }