FindPath() private method

private FindPath ( Vector2 startPos, Vector2 targetPos ) : IEnumerator
startPos Vector2
targetPos Vector2
return IEnumerator
 public void FindPath()
 {
     ResetColors(Color.white);
     pathfinding.grid = roadGrid.GetRoadTiles();
     pathfinding.FindPath(start.location, stop.location);
     ColorPoints();
 }
Ejemplo n.º 2
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("First pos: " + player.transform.position);
            Vector3 mouseWorldPosition = GetMouseWorldPosition();
            pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y); //gets the (x,y) values of the node you clicked on
            int[]           playerXY = GetPlayerPosicion(player.transform);        //gets the (x,y) values of the player GameObject
            List <PathNode> path     = pathfinding.FindPath(playerXY[0], playerXY[1], x, y);
            if (path != null)
            {
                StartCoroutine(MovePlayer(path));
            }
            else
            {
                Debug.Log("No available path?");
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector3 mouseWorldPosition = GetMouseWorldPosition();
            pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
            pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
        }
    }
Ejemplo n.º 3
0
    private void UpdateNodes()
    {
        nodesToGoal.Clear();
        List <List <Vector3> > temp = new List <List <Vector3> >();

        foreach (Goal goal in StageManager.Instance.BattleManager.GoalList)
        {
            int lowestNodes = int.MaxValue; int lowestIndex = 0;
            temp.Clear();

            for (int i = 0; i < StageManager.Instance.PathTilemap.Count; i++)
            {
                UnityEngine.Tilemaps.Tilemap pathMap = StageManager.Instance.PathTilemap[i];
                temp.Add(Pathfinding.FindPath(transform.position, goal.transform.position, pathMap, false));
                if (temp[i].Count > 1 && temp[i].Count < lowestNodes)
                {
                    lowestNodes = temp[i].Count;
                    lowestIndex = i;
                }
            }

            nodesToGoal.Insert(goal.goalIndex, temp[lowestIndex]);
        }
        nodesAreOutdated = false;
    }
Ejemplo n.º 4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            path = pathfinding.FindPath(transform.position, player.position);

            if (path != null)
            {
                foreach (var item in path)
                {
                    Debug.Log($"Path: {item.x}, z:{item.z}");
                }
            }
        }

        if (path != null)
        {
            currentPathIndex  = 0;
            agent.destination = path[currentPathIndex];

            if (Vector3.Distance(transform.position, agent.destination) < 0.5f && currentPathIndex < path.Count)
            {
                currentPathIndex++;
                agent.destination = path[currentPathIndex];
            }
        }
    }
Ejemplo n.º 5
0
    IEnumerator MoveToTarget()
    {
        Pathfinding.FindPath(Location, target, this, playerControlled);
        int searchRange = 1;

        while (!Pathfinding.HasPath && searchRange <= maxSearchRange)
        {
            Debug.Log("Checking alternative path with merchant");
            List <HexCell> alternativeTargetCells = CellFinder.GetCellsWithinRange(target, searchRange, (c) => c.Traversable == true, (c) => c.IsFree);
            foreach (var item in alternativeTargetCells)
            {
                Pathfinding.FindPath(Location, item, this, playerControlled);
                if (Pathfinding.HasPath)
                {
                    break;
                }
            }
            searchRange *= 2;
        }
        if (Pathfinding.HasPath)
        {
            yield return(Travel(Pathfinding.GetReachablePath(this, out int cost)));

            Pathfinding.ClearPath();
        }
        if (Location == target)
        {
            routeIndex++;
            if (routeIndex >= route.RouteStops.Length)
            {
                routeIndex = 0;
            }
            target = null;
        }
    }
Ejemplo n.º 6
0
    public void StartMovement(Vector3 destination)
    {
        destination = Helpers.ReturnTilePosition(StageManager.Instance.HighlightMap.tilemap, destination, -3);
        Vector3 vector = destination - transform.position;
        float   dist   = vector.sqrMagnitude;

        if (dist <= 0.0f)
        {
            movementNodes.Clear();
            movementNodes.Add(destination);
            IsMoving         = true;
            NextMovementNode = 0;
        }
        else
        {
            Tilemap    tilemap  = StageManager.Instance.HighlightMap.tilemap;
            Vector3Int cellPos  = tilemap.WorldToCell(transform.position);
            Vector3    startPos = tilemap.GetCellCenterWorld(cellPos);
            startPos.z    = -3;
            movementNodes = Pathfinding.FindPath(startPos, destination, StageManager.Instance.HighlightMap.tilemap, true);
            if (movementNodes != null)
            {
                NextMovementNode = 1;
                IsMoving         = true;
            }
        }
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 position = UtilsClass.GetMouseWorldPosition();
            Vector3 offset   = new Vector3(0, 0);
            pathfinding.GetGrid().GetXY(position, out int x, out int y);
            List <PathNode> path = pathfinding.FindPath(0, 0, x, y);
            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    //Debug.DrawLine(new Vector3(path[i].x, path[i].y) * 5f + Vector3.one * 5f + offset, new Vector3(path[i + 1].x, path[i + 1].y) * 5f + Vector3.one * 2.5f + offset, Color.red, 10f);
                    //Debug.Log(path[i].x.ToString() + "," + path[i].y.ToString());
                }
            }

            //HeatMapGridObject heatMapGridObject = ground.GetGridObject(position);
            //if (heatMapGridObject != null)
            //{
            //    heatMapGridObject.AddValue(5);
            //    ground.SetGridObject(position, heatMapGridObject);
            //    EventManager.TriggerEvent("test");

            //}
            //ground.SetValue(position, true);
        }

        //if (Input.GetMouseButtonDown(1))
        //{
        //    Vector3 position = UtilsClass.GetMouseWorldPosition();
        //    pathfinding.GetGrid().GetXY(position, out int x, out int y);
        //    pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
        //}
    }
Ejemplo n.º 8
0
    public void Execute(System.Collections.Generic.List <Entity> entities)
    {
        var lastBlocked = entities.SingleEntity();

        Entity m;
        var    movers = _groupMover.GetEntities();

        for (int i = 0; i < movers.Length; i++)
        {
            m = movers [i];

            path = Pathfinding.FindPath(m.standOn.node, m.goal.node, _pool.nodeDistance.D, _pool.nodeDistance.D2);
            if (path == null)               // can not find path
            {
                lastBlocked.RemoveLastBlocked().IsUnblockable(true);
                return;
            }
        }

        lastBlocked.lastBlocked.node.ReplaceNode(true).IsBlocked(true).RemoveLastBlocked();

        var uns = _groupUnblockable.GetEntities();

        for (int i = 0; i < uns.Length; i++)
        {
            uns [i].IsUnblockable(false);
        }
        _pool.NextPhase();
    }
Ejemplo n.º 9
0
    public void MoveEnemy()
    {
        Vector2 dis = target.position - transform.position;

        isMove = true;
        if (dis.sqrMagnitude > distance * distance)
        {
            isMove = false;
            return;
        }
        gridPath.CreateGrid();
        Vector2 dir  = pathfinding.FindPath(transform.position, target.position);
        int     xDir = Mathf.RoundToInt(dir.x - transform.position.x);
        int     yDir = Mathf.RoundToInt(dir.y - transform.position.y);

        if (xDir > 0)
        {
            onLeft = false;
            animator.ResetTrigger("Left");
            animator.SetTrigger("Right");
            animator.SetBool("LeftBool", false);
        }
        else if (xDir < 0)
        {
            onLeft = true;
            animator.ResetTrigger("Right");
            animator.SetTrigger("Left");
            animator.SetBool("LeftBool", true);
        }

        AttemptMove <Player>(xDir, yDir);
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (GameData.instance.devTools)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3 mouseWorldPos = worldCamera.ScreenToWorldPoint(Input.mousePosition);
                mouseWorldPos.z = 0f;

                Vector2Int      XY   = pathfinding.GetGrid().GetXY(mouseWorldPos);
                List <PathNode> path = pathfinding.FindPath(new Vector2Int(1, 1), XY);

                if (path != null)
                {
                    for (int i = 0; i < path.Count - 1; i++)
                    {
                        Debug.DrawLine(new Vector3(path[i].x - 15, path[i].y - 9) * 1f + Vector3.one * 0.5f, new Vector3(path[i + 1].x - 15, path[i + 1].y - 9) * 1f + Vector3.one * 0.5f, Color.red, 5f);
                    }
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                Vector3 mouseWorldPos = worldCamera.ScreenToWorldPoint(Input.mousePosition);
                mouseWorldPos.z = 0f;

                Vector2Int XY = pathfinding.GetGrid().GetXY(mouseWorldPos);
                pathfinding.GetNode(XY.x, XY.y).ToggleIsWalkable();
            }
        }
    }
Ejemplo n.º 11
0
        private void PickState()
        {
            Tile tile = null;

            TileCoordinates c           = Position.ToTileCoordinates();
            Tile            currentTile = GameLoop.World.TileGrid[c.X, c.Y];

            if (currentTile.HasSubtile(typeof(CashRegister)))
            {
                SetState("Idle");
                CurrentState.CurrentAnimation.SpriteFX = RNGMachine.Instance.Generator.Next(2) == 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.FlipHorizontally;
                return;
            }

            foreach (Tile t in GameLoop.World.ImportantTiles)
            {
                if (GameLoop.World.ContainingEntities(t).Count(x => x.GetType() == typeof(Worker)) < 1 && t.HasSubtile(typeof(CashRegister)))
                {
                    tile = t;
                    break;
                }
            }

            if (tile == null)
            {
                SetState("Wander");
                return;
            }

            path.Clear();

            path = Pathfinding.FindPath(GameLoop.World.PathingGrid, Position, Tile.GetCenter(tile));
            SetState("TracingPath");
        }
Ejemplo n.º 12
0
    public bool CanCompleteLevel(List <Vector2Int> holes)
    {
        _pathfinding  = new Pathfinding(_width, _height, moveDiagonally: false);
        _finishedPath = new List <PathNode>();
        _testPath     = new List <PathNode>();

        var endY   = MapCubeEnd.Pos.y - 1;
        var startY = MapCubeStart.Pos.y + 1;

        _pathfinding.SetAllWalkable(true);
        _pathfinding.SetSomeIsWalkable(holes, false);

        List <PathNode> path = _pathfinding.FindPath(MapCubeStart.Pos.x, startY, MapCubeEnd.Pos.x, endY);

        if (path == null || path.Count == 0)
        {
            if (DebugPathfinding)
            {
                Debug.Log("No Path to End");
            }
            return(false);
        }

        if (DebugPathfinding)
        {
            foreach (PathNode pNode in path)
            {
                Debug.Log("path: " + pNode.ToString());
                Game._.LevelController.MapCubes[pNode.x, pNode.y].ChangeColor(PathColor.Pink);
            }
        }
        return(true);
    }
Ejemplo n.º 13
0
    private void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            Vector2         touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
            Grid <PathNode> grid          = pathfinding.GetGrid();

            grid.GetXY(touchPosition, out int x, out int y);
            List <PathNode> path = pathfinding.FindPath(0, 0, x, y);
            // Debug.Log("Path From 0,0 to " + x + "," + y);
            // Debug.Log(path.Count);

            // mob.SetTargetPosition(touchPosition);

            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    Debug.Log(path[i].ToString());
                    Debug.DrawLine(new Vector3(path[i].x, path[i].y) * grid.GetCellSize() + Vector3.one * grid.GetCellSize() * .5f + grid.GetOriginPosition(), new Vector3(path[i + 1].x, path[i + 1].y) * grid.GetCellSize() + Vector3.one * grid.GetCellSize() * .5f + grid.GetOriginPosition(), Color.red, 5f);
                }
            }
            // grid.SetGridObject(touchPosition, true);
        }
    }
Ejemplo n.º 14
0
        public void PopulateGrid()
        {
            gridLocations.Clear();

            foreach (EntryPoint entryPoint in TerraFirma.Instance.TubeNetworkLayer[Container.Position].Network.GetEntryPoints())
            {
                if (entryPoint == Container)
                {
                    continue;
                }

                UIEntryPointItem entryPointItem = new UIEntryPointItem(entryPoint)
                {
                    Width  = (0, 1),
                    Height = (60, 0)
                };
                entryPointItem.OnClick += (evt, element) =>
                {
                    TubularNetwork  network = TerraFirma.Instance.TubeNetworkLayer[Container.Position].Network;
                    Stack <Point16> path    = Pathfinding.FindPath(network.Tiles, Container.Position, entryPoint.Position);

                    TransportingPlayer transfer = new TransportingPlayer(Main.LocalPlayer, path);

                    network.TransportingPlayers.Add(transfer);

                    BaseLibrary.BaseLibrary.PanelGUI.UI.CloseUI(Container);
                };
                gridLocations.Add(entryPointItem);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gives a random secret in string form
        /// </summary>
        /// <returns></returns>
        private string GetRandomSecret()
        {
            Cave cave = GameController.Map.Cave;

            switch (Rand.Next(4))
            {
            case 0:     // How many tiles away the nearest bats are
                return(String.Format("The nearest bats are {0} tiles away",
                                     cave.Rooms.
                                     Where(r => r.HasBats).
                                     Select(r => Pathfinding.FindPath(r, cave[GameController.Map.PlayerRoom], cave, false).Count).
                                     OrderBy(r => r).
                                     First()));

            case 1:     // How many tiles away the nearest pit is
                return(String.Format("The nearest pit is {0} tiles away",
                                     cave.Rooms.
                                     Where(r => r.HasPit).
                                     Select(r => Pathfinding.FindPath(r, cave[GameController.Map.PlayerRoom], cave, false).Count).
                                     OrderBy(r => r).
                                     First()));

            case 2:     // The room number of the wumpus
                return(String.Format("The wumpus' room number is {0}",
                                     GameController.Map.Wumpus.Location));

            case 3:     // Current player room number
                return(String.Format("The player's room number is {0}",
                                     GameController.Map.PlayerRoom));

            default: throw new Exception();
            }
        }
Ejemplo n.º 16
0
    private void OnFinished()
    {
        Globals.isRunning = true;

        // Get random grid X and Y
        int nextX = Random.Range(0, GRID_X);
        int nextY = Random.Range(0, GRID_Y);

        StatsHandler.Instance.log("Zooming to " + nextX + "," + nextY);

        // Get the world position of x and y
        Vector3 mouseWorldPosition = grid.GetWorldPosition(nextX, nextY);

        // Find path
        pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
        List <PathNode> path = pathfinding.FindPath(lastX, lastY, x, y);

        // Update character
        characterPathfinding.SetTargetPosition(mouseWorldPosition);

        // Keep track of previous tile
        if (path != null)
        {
            lastX = x;
            lastY = y;
        }

        // Use StatsHandler to keep track of cycles
        StatsHandler.Instance.updateCycles();
    }
Ejemplo n.º 17
0
 private void NearbyState(GridPosition pos)
 {
     foreach (var path in State.Dictionary)
     {
         if (path.Value.Contains(pos))
         {
             var index = path.Value.IndexOf(pos);
             if (index == 0)
             {
                 continue;
             }
             path.Value.RemoveRange(0, index);
         }
         else
         {
             if (Map.Value.Neighbours(pos).ContainsPos(path.Value[0]))
             {
                 path.Value.Insert(0, pos);
             }
             else
             {
                 State.Dictionary[path.Key] = Pathfinding.FindPath(pos, path.Key.GPosition, Map.Value).Path;
             }
         }
     }
 }
Ejemplo n.º 18
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 clickPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            pathFinding.NodeGrid.WorldToCellPos(clickPos, out int x, out int y);
            List <PathNode> path = pathFinding.FindPath(0, 0, x, y);

            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    Debug.DrawLine(new Vector3(path[i].x, path[i].y), new Vector3(path[i + 1].x, path[i + 1].y), Color.green, 100f);
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector3  clickPos    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            PathNode currentNode = pathFinding.NodeGrid.GetGridObject(clickPos);
            currentNode.ToggleWalkable();
            pathFinding.NodeGrid.UpdateValue(currentNode.x, currentNode.y);
        }
    }
Ejemplo n.º 19
0
    // Returns a list of points towards a target from where we're standing.
    public List <Point> FindPathTo(int x, int z, Pathfinding.DistanceType distanceType)
    {
        Point _from = new Point(xPos, zPos);
        Point _to   = new Point(x, z);

        return(Pathfinding.FindPath(BattleManager.instance.map.walkGrid, _from, _to, distanceType));
    }
Ejemplo n.º 20
0
    private void Update()
    {
        // GameObject pacman = GameObject.Instantiate(pacmanPrefab, pacmanParent);
        Vector3 mouseWorldPosition = GetMouseWorldPosition();

        Debug.Log(mouseWorldPosition.x + ", " + mouseWorldPosition.y);
        pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
        List <PathNode> path = pathfinding.FindPath(0, 0, x, y);


        Debug.Log("inside Input");
        if (path != null)
        {
            Debug.Log("inside path");
            for (int i = 0; i < path.Count - 1; i++)
            {
                Debug.DrawLine(new Vector3(path[i].x, path[i].y) * 10f + Vector3.one * 5f, new Vector3(path[i + 1].x, path[i + 1].y) * 10f + Vector3.one * 5f, Color.green);
            }
        }


        if (Input.GetMouseButtonDown(1))
        {
            Vector3 mouseWorldPosition2 = GetMouseWorldPosition();
            pathfinding.GetGrid().GetXY(mouseWorldPosition2, out int x2, out int y2);
            pathfinding.GetNode(x2, y2).SetIsWalkable(!pathfinding.GetNode(x2, y2).isWalkable);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var worldPosition = UtilsClass.GetMouseWorldPosition();
            var cellPosition  = pathfinding.Grid.WorldToCell(worldPosition);

            List <PathNode> path = pathfinding.FindPath(cellPosition, startFromLastNode);

            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    Vector3 start = new Vector3(path[i].Position.x, path[i].Position.y) * 10f + Vector3.one * 5f;
                    Vector3 end   = new Vector3(path[i + 1].Position.x, path[i + 1].Position.y) * 10f + Vector3.one * 5f;
                    Debug.DrawLine(start, end, Color.green, 10f);
                }
            }
        }

        // Put walls
        if (Input.GetMouseButtonDown(1))
        {
            Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition();
            var     cellPosition       = pathfinding.Grid.WorldToCell(mouseWorldPosition);
            var     node = pathfinding.Grid.GetCell(cellPosition.x, cellPosition.y);

            if (node != null)
            {
                node.IsWalkable = !node.IsWalkable;
            }
        }
    }
Ejemplo n.º 22
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         mouseWorldPosition.z = 0;
         pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
         List <PathNode> path = pathfinding.FindPath(0, 0, x, y);
         if (path != null)
         {
             for (int i = 0; i < path.Count - 1; i++)
             {
                 Debug.DrawLine(new Vector3(path[i].x, path[i].y) * 4f + Vector3.one, new Vector3(path[i + 1].x, path[i + 1].y) * 4f + Vector3.one);
             }
         }
         characterPathfinding.SetTargetPosition(mouseWorldPosition);
     }
     if (Input.GetMouseButtonDown(1))
     {
         Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         mouseWorldPosition.z = 0;
         pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
         pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
     }
 }
Ejemplo n.º 23
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition();
            pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
            List <PathNode> path = pathfinding.FindPath(0, 0, x, y);
            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    Debug.DrawLine(new Vector3(path[i].x, path[i].y) * 10f + Vector3.one * 5f, new Vector3(path[i + 1].x, path[i + 1].y) * 10f + Vector3.one * 5f, Color.green, 5f);
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition();
            pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
            pathfinding.GetNode(x, y).SetValue();
            pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
        }

        if (Input.GetMouseButtonDown(2))
        {
            Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition();
            pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
            pathfinding.GetNode(x, y).SetValueBoue();
            pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
            pathfinding.GetNode(x, y).SetIsWalkable(!pathfinding.GetNode(x, y).isWalkable);
        }
    }
Ejemplo n.º 24
0
    // Calculate the next point on the Creatures Patrol
    Point NextPointOnPatrol()
    {
        // The Target Coord is determined by the Current Leg of the Creature's Patrol
        int targetXCoord = patrolEnd.x;
        int targetYCoord = patrolEnd.y;

        if (onReturnLegOfPatrol)
        {
            targetXCoord = patrolStart.x;
            targetYCoord = patrolStart.y;
        }

        // Determine the Starting Position and the Target Position
        int currentX = (int)transform.position.x;
        int currentY = (int)transform.position.y;

        Point startPos  = new Point(currentX, currentY);
        Point targetPos = new Point(targetXCoord, targetYCoord);

        // Calculate the Best Path to the Target Point
        List <Point> path          = Pathfinding.FindPath(pathingCosts, startPos, targetPos);
        Point        pointToMoveTo = path [0];

        // Update the Leg of the Patrol
        if (pointToMoveTo.x == targetPos.x && pointToMoveTo.y == targetPos.y)
        {
            onReturnLegOfPatrol = !onReturnLegOfPatrol;
        }

        return(pointToMoveTo);
    }
Ejemplo n.º 25
0
//
//	void OnDrawGizmos(){
//		Gizmos.DrawWireCube(transform.position,new Vector3(gridWorldSize.x,1,gridWorldSize.y));
//		if (grid != null) {
//			foreach(Node n in grid){
//				Gizmos.color = (n.walkable) ? Color.white : Color.red;
//				if (path != null)
//					if (path.Contains (n))
//						Gizmos.color = Color.black;
//				Gizmos.DrawCube (n.worldPosition, Vector3.one * (nodeDiameter - .1f));
//			}
//		}
//	}
    public void Draw()
    {
        grid = null;
        foreach (GameObject g in GameObject.FindGameObjectsWithTag("Nodes"))
        {
            Destroy(g);
        }
        ;
        CreateGrid();
        pathfinder.FindPath();
        //Gizmos.DrawWireCube(transform.position,new Vector3(gridWorldSize.x,1,gridWorldSize.y));
        if (grid != null)
        {
            foreach (Node n in grid)
            {
                if (n.walkable)
                {
                    if (path.Contains(n))
                    {
                        Instantiate(blackNode, n.worldPosition, Quaternion.identity);
                    }
                    else
                    {
                        Instantiate(whiteNode, n.worldPosition, Quaternion.identity);
                    }
                }
                else if (!n.walkable)
                {
                    Instantiate(redNode, n.worldPosition, Quaternion.identity);
                }
            }
        }
    }
Ejemplo n.º 26
0
    public void MoveTo(GameObject target)
    {
        if (isPraying)
        {
            return;
        }
        if (isInJob)
        {
            return;
        }
        newPathFound  = true;
        isInGoal      = false;
        lookCorrected = false;
        if (gameObject.Equals(target.gameObject))
        {
            newPathFound   = false;
            ableToStart    = true;
            routineRunning = false;
            return;
        }

        pathfinding.seeker = gameObject.transform;
        pathfinding.target = target.transform;

        grid.Create();
        grid.player = gameObject.transform;
        if (!grid.NodeFromWorldPoint(new Vector3(target.transform.position.x, target.transform.position.y, 0)).walkable)
        {
            return;
        }
        pathfinding.FindPath(pathfinding.seeker.position, pathfinding.target.position);
        ableToStart = true;
        StartCoroutine(TryMoving());
        FMODUnity.RuntimeManager.PlayOneShot(walkingCommand);
    }
Ejemplo n.º 27
0
    public virtual bool BasicAttack(Charecter Target, bool isAIAttack = false)
    {
        bool success = false;

        if (equipedWeapon.Range == 1)
        {
            Debug.Log(Target);
            if (((Target.posX - posX) >= -1 && (Target.posX - posX) <= 1) && ((Target.posY - posY) >= -1 && (Target.posY - posY) <= 1))
            {
                success = true;
            }
        }
        else
        {
            if (pathfinder.FindPath(Target) <= equipedWeapon.Range)
            {
                success = true;
            }
        }
        attemptingAttack = 0;
        pathfinder.ClearLines();
        if (success)
        {
            if (Target.isPlayerUnit && !isAIAttack)
            {
                return(false);
            }
            hasAttackedForTurn = true;
            Target.TakeDamege(equipedWeapon.Attack);
        }
        return(success);
    }
Ejemplo n.º 28
0
 public void SetTarget(Vector3 value)
 {
     target = value;
     if (target != Vector3.zero)
     {
         path = pathfinding.FindPath(transform.position, target);
     }
 }
Ejemplo n.º 29
0
 public void MoveTo(GameObject target, float movementSpeed)
 {
     allowedMovement      = true;
     currentMovementSpeed = movementSpeed;
     path             = Pathfinding.FindPath(gameObject, target);
     currentPathIndex = 0;
     currentTarget    = target.transform.position;
 }
 public void Initialize(IWorldData worldData)
 {
     sprite   = worldData.GetWorldObject(worldObjectId).GetComponent <Sprite>();
     movement = worldData.GetWorldObject(worldObjectId).GetComponent <Movement>();
     path     = pathfinding.FindPath(sprite.TilePosition, goalTilePosition, worldData.GetComponents <ICollisionComponent>());
     index    = 0;
     IsDone   = false;
 }