Beispiel #1
0
	public void OnMouseOverTile(Vector3 position){
		Node node = grid.NodeFromWorldPoint (position);
		if (node == null)
			return;
		if (additionalMouseoverUpScaledNodes != null) {
			for (int i=0; i<additionalMouseoverUpScaledNodes.Count; ++i){
				additionalMouseoverUpScaledNodes[i].visualizationTile.ScaleDown();
			}
			additionalMouseoverUpScaledNodes.Clear();
		}
		node.visualizationTile.ScaleUp ();
		switch (turnState) {
			case TurnState.DEFAULT:
				if (node.Unit != null && GetPlayer (turn).troop.units.Contains (node.Unit)) {
					//own unit
				}
				break;
			case TurnState.SPELLSELECTED:
				List<Node> validSpellTargets = ValidSpellTargets(SelectedSpell.targetinType);
				if (validSpellTargets.Contains(node)){
					node.visualizationTile.ScaleUp();
					additionalMouseoverUpScaledNodes.Add(node);
					if (SelectedSpell.targetinType==TargetingType.TARGETEDAOE){
						Node[] neighbours = grid.GetNeighbours(node);
						for (int i=0; i< neighbours.Length; ++i){
							if (neighbours[i]!=null){
								neighbours[i].visualizationTile.ScaleUp();
								additionalMouseoverUpScaledNodes.Add(neighbours[i]);
							}
						}
					}
				}
				break;
			case TurnState.UNITSELECTED:
				if (node.Unit == null && selectedUnitsValidMovement!=null && selectedUnitsValidMovement.Contains(node)) {
					bool pathFound=false;
					Node[] path=null;
					for (int i=0; i< SelectedUnit.Unit.TriggableAbilities.Count; ++i){
						if (SelectedUnit.Unit.TriggableAbilities[i] is IOverrideMovement){
							path =  ((IOverrideMovement)SelectedUnit.Unit.TriggableAbilities[i]).FindPath(SelectedUnit.worldPosition , node.worldPosition, pathFinding);
							pathFound=true;
						}
					}
					if (!pathFound) {
						path = pathFinding.FindPath(SelectedUnit.worldPosition, node.worldPosition);
					}
					
					for (int i=0; i<path.Length; ++i){
						path[i].visualizationTile.ScaleUp();
						additionalMouseoverUpScaledNodes.Add(path[i]);
					}
				} else if (node.Unit!=null && !GetPlayer (turn).troop.units.Contains (node.Unit)) {
					if (!(selectedUnit.Unit.ranged && !EnemyInNeighbour(selectedUnit)) && selectedUnit.Unit.ableToAttack){
						mouseInput.OnMouseStayOnTile += MouseStayOnTile;
					}
				}
				break;
		}
	}
Beispiel #2
0
    public bool SetDestination(Tile tile)
    {
        if (tile.Type != TileType.Space)
        {
            //  Need to find path to
            //  if we are on our way to the docking, allow the pathfinding to walk over TileType.Docking tiles
            //
            var pathfinder = new PathFinding(_currentState == CharacterState.GotoPickUpTile);
            _path = pathfinder.FindPath(CurrentTile, tile);

            if (_path != null)
            {
                DestinationTile = tile;
            }
            else
            {
                if (_currentState != CharacterState.WanderAround &&
                    _currentState != CharacterState.Idle)
                {
                    Log($"No Path found [{_currentState}] from {CurrentTile.Position} to {tile.Position}");
                }
            }
        }

        return(DestinationTile != null);
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        GameObject cone = Resources.Load <GameObject>("cone");

        _head = GameObject.Instantiate(cone);
        _head.transform.SetParent(this.transform);
        _rightLeg = GameObject.Instantiate(cone);
        _rightLeg.transform.SetParent(this.transform);
        _leftLeg = GameObject.Instantiate(cone);
        _leftLeg.transform.SetParent(this.transform);

        _head.transform.localScale     = new Vector3(0.8f, 0.8f, 1.2f);
        _rightLeg.transform.localScale = new Vector3(0.3f, 0.3f, 0.5f);
        _leftLeg.transform.localScale  = new Vector3(0.3f, 0.3f, 0.5f);

        _leftLeg.transform.localRotation  = Quaternion.Euler(90, 0, 0);
        _rightLeg.transform.localRotation = Quaternion.Euler(90, 0, 0);

        _leftLeg.transform.localPosition  = new Vector3(0f, -0.25f, -0.5f);
        _rightLeg.transform.localPosition = new Vector3(0f, -0.25f, 0.5f);

        ColorIn();

        transform.position = Terrain.Instance.GetGrid().CellToWorld(new Vector3Int(pos.x, 0, pos.y)) + Vector3.up * Terrain.Instance.GetWorldHeight(new Vector3(pos.x, 0, pos.y));

        objective       = Terrain.Instance.GetNearestTree(pos).gameObject;
        pathToObjective = PathFinding.FindPath(pos, objective.GetComponent <Tree>().pos);
        pathToObjective.RemoveAt(0); // Remove objective so we're only standing next to it.
        nextSquare = pathToObjective.Count - 1;
    }
Beispiel #4
0
    private void SelectGridPosition()
    {
        var mouse         = Input.mousePosition;
        var worldPosition = Camera.main.ScreenToWorldPoint(mouse);

        grid.SetNodeValue(worldPosition, "32");

        if (!grid.IsWolrdPositionInsideGrid(worldPosition))
        {
            return;
        }

        mouseInputs.Add(worldPosition);
        if (mouseInputs.Count == 2)
        {
            var startPos = grid.GetGridPostion(mouseInputs.First());
            var endPos   = grid.GetGridPostion(mouseInputs.Last());
            var path     = pathFindingGrid.FindPath(new int2(startPos), new int2(endPos));

            mouseInputs.Clear();
            if (path.Count() == 1)
            {
                Debug.Log("Caminho não encontrado");
                return;
            }

            foreach (var p in path)
            {
                Debug.Log(p);
            }

            grid.DrawLines(path.ToArray());
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        ClickTile();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (path.Count != 0)
            {
                start = end = null;
                path.Clear();
            }
            else
            {
                if (PathFinding.FindPath(start.GridPosition, end.GridPosition))
                {
                    path = PathFinding.Path;
                    //DrawPath();
                }
                else
                {
                    start = end = null;
                    UnityEngine.Debug.Log("Not found");
                }
            }
        }
    }
Beispiel #6
0
 /// <summary>
 /// Updates path.
 /// </summary>
 protected void UpdatePath()
 {
     if ((tankLevel == 1) || (tankLevel == 11))
     {
         Vector2 newPoint = new Vector2();
         newPoint.y = GameManager.playerInstance.transform.position.y;
         newPoint.x = (GameManager.playerInstance.transform.position.x - 6.5f) * -1;
         path       = PathFinding.FindPath(this.transform.position, newPoint);
     }
     else if ((tankLevel == 2) || (tankLevel == 12))
     {
         path = PathFinding.FindPath(this.transform.position, GameManager.playerInstance.transform.position);
     }
     else if ((tankLevel == 3) || (tankLevel == 13))
     {
         path = PathFinding.FindPath(this.transform.position, (new Vector2(6.5f, 0.5f))); // base position
     }
     if (path != null)
     {
         followPathTimeStamp = Time.time;
         DebugVisualHelper.DrawPath(path);
         followingPath = true;
         pathPoints    = 0;
         GetDirectionFromVector();
     }
 }
Beispiel #7
0
    protected bool AttackPlayer()
    {
        // FULL SPEED AHEAD
        targetMovementSpeed = 1.0f;

        // Look for player towards the last known position
        // Calculate intercept vector
        Vector3 dir = (playerPos - transform.position).normalized;

        // Find nearest cell with cover from player
        PathNode coverNode;
        Vector3  coverPos;

        if (currentPath == null)
        {
            if (FindCover(out coverNode, out coverPos))
            {
                // Get node position
                Vector3 nodePos = cellGrid.GetCellPos(
                    cellGrid.Grid[(int)coverNode.Position.x, (int)coverNode.Position.y]);

                // Path find to cover (or just the farthest away node if we didn't find cover)
                currentPath = PathFinding.FindPath(currentNode, coverNode);

                // If the path length is 1 (we're already on the cell), move towards hidePos
                if (currentPath.Count == 1)
                {
                    Move((coverPos - transform.position));
                }
            }
            // If we couldn't find any cover, just run away
            else
            {
                Move(-dir);
            }
        }

        // If we can see the player, shoot at it
        if (CanSeeObjectOnLayer(dir, playerLayer, "Player"))
        {
            dir = Quaternion.AngleAxis(Random.Range(-0.5f, 0.5f) * LOOK_PLAYER_JITTER, Vector3.forward) *
                  (playerPos - transform.position).normalized;

            TurnTowards(dir);

            // Shoot once we're facing the right direction
            if (Vector3.Angle(dir, FacingDirection) < 1.0f)
            {
                Fire();
            }
        }
        // Otherwise, look for it
        else
        {
            SwitchState(State.LOOK_FOR_PLAYER);
            return(false);
        }

        return(true);
    }
Beispiel #8
0
 public static void AddEvent(string EventType, GameObject Executor, GameObject TargetObject)
 {
     ClearUnit(Executor);
     if (KeyTerm.MOVE_CMD == EventType)
     {
         if (Executor.transform.parent.GetComponent <Tile>().XCor == TargetObject.transform.parent.GetComponent <Tile>().XCor&& Executor.transform.parent.GetComponent <Tile>().YCor == TargetObject.transform.parent.GetComponent <Tile>().YCor)
         {
             Debug.Log(Message.SAME_LOCATION);
             return;
         }
         else
         {
             Executor.GetComponent <Unit>().MoveNeed  = TargetObject.GetComponent <Tile>().MoveRequire;
             Executor.GetComponent <Unit>().MoveRoute = PathFinding.FlipRoute(PathFinding.FindPath(Executor.transform.parent.gameObject, Executor.transform.parent.gameObject, TargetObject.transform.parent.gameObject));
         }
     }
     else if (KeyTerm.ATTACK_CMD == EventType)
     {
         if (null == TargetObject.GetComponent <Unit>())
         {
             Debug.Log(Message.NOT_A_UNIT);
             return;
         }
         else
         {
             Executor.GetComponent <Unit>().MoveNeed = Executor.GetComponent <Unit>().AttackNeed;
         }
     }
     Target[Executor.GetComponent <Unit>().UnitID]  = TargetObject;
     Executor.GetComponent <Unit>().MovePoint       = 0;
     Executor.GetComponent <Unit>().Action          = EventType;
     Executor.GetComponent <SpriteRenderer>().color = Color.red;
 }
Beispiel #9
0
    public bool Move(Cell targetCell, bool animate, int distance)
    {
        if (animate)
        {
            List <Cell> path = PathFinding.FindPath(MapInfos, CurrentCell, targetCell);
            if (path != null)
            {
                Movement.StartMovement(path, CurrentCell);
                ProjectionManager.SelectPath(path);
            }
        }
        else
        {
            transform.position = targetCell.GetVector3Position();
        }

        if (CurrentCell != null)
        {
            CurrentCell.IsTaken = null;
        }
        CurrentCell         = targetCell;
        CurrentCell.IsTaken = this;

        if (distance > 0)
        {
            AttributesSheet.AddCostAttribute(new Attribute(AttributeType.MovementPoint, -distance, PropertyType.Value, 1));
            CombatUIManager.UpdateMovementPoint(AttributesSheet.GetAttribute(AttributeType.MovementPoint));
        }
        return(true);
    }
Beispiel #10
0
    // Listen for messages from other NPCs
    protected void SawPlayer(Vector3 pos)
    {
        if (currentNode == null)
        {
            return;
        }

        if (currentState == State.PATROL_LEVEL ||
            currentState == State.MAP_LEVEL)
        {
            playerPos    = pos;
            gotPlayerPos = true;

            // Try and generate a path to the player
            List <PathNode> newPath = PathFinding.FindPath(currentNode,
                                                           cellGrid.GetPathfindingNode(cellGrid.GetCellAtPos(playerPos)));

            // If we succeeded in generating a path & we aren't currently chasing the player
            // Switch to going to find the player
            if (newPath.Count != 0)
            {
                currentPath = newPath;
                SwitchState(State.LOOK_FOR_PLAYER);
            }
        }
    }
Beispiel #11
0
    private void GetPath()
    {
        if (aStar == null)
        {
            Init();
        }
        else
        {
            StoreNode(aStar.GetCurrentNode(transform.position));
            currentNodeTimeSpent = maximumTimeSpentByNode;
            MindMap mindMap = GetComponent <MindMap> ();
            targetRoomPoint = mindMap.GetRoomPoint(roomToGo);
            if (targetRoomPoint != null)
            {
                path = aStar.FindPath(transform.position, targetRoomPoint.transform.position);
                if (path != null)
                {
                    isFinalTargetRoomPoint = true;
                    aStar.SetPath(path);
//					Debug.Log ("Path OK");
                }
                else
                {
                    Debug.Log("Cannot move");
                }
            }
            else
            {
                Debug.Log("The room for " + roomToGo + "does not exist");
            }
        }
    }
Beispiel #12
0
    public WorldTile GetAndSetDestinationTile(Vector3Int currentPosition, List <Vector3Int> deniedDestinations)
    {
        cellsInMoveRadius = GetCellsInMoveRadius(currentPosition);

        WorldTile destinationTile = GetDestinationTile(currentPosition, cellsInMoveRadius, deniedDestinations);

        //if we clicked on a tile
        if (destinationTile != null)
        {
            WorldTile enemyTile;
            if (GameTiles.tiles.TryGetValue(currentPosition, out enemyTile))
            {
                enemyTile.hasEnemy    = false;
                enemyTile.enemyEntity = null;
            }

            //lets chart a destination path to the target square
            squaresToTravelTo = PathFinding.FindPath(currentPosition, destinationTile.WorldLocation);

            //if we can get there, grab the first step
            if (squaresToTravelTo.Count > 0)
            {
                this.destinationTile = squaresToTravelTo.Pop();
            }
        }

        return(destinationTile);
    }
Beispiel #13
0
        static void Main(string[] args)
        {
            Height = Screen.PrimaryScreen.Bounds.Height;
            Width  = Screen.PrimaryScreen.Bounds.Width;

            _Window.SetVerticalSyncEnabled(true);

            #region Events
            _Window.KeyPressed         += _Window_KeyPressed;
            _Window.MouseButtonPressed += _Window_MouseButtonPressed;
            #endregion

            while (IsRunning)
            {
                _Window.DispatchEvents();

                _Window.Clear(Color.Black);

                PathFinding x = new PathFinding();
                x.FindPath(new SFML.System.Vector2i(0, 0), new SFML.System.Vector2i(29, 24), ref grid);

                grid.Draw(_Window);

                _Window.Display();
            }
        }
Beispiel #14
0
    private void SetDestinationTile(Vector3Int playerPos)
    {
        Vector3 point      = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        var     worldPoint = new Vector3Int(Mathf.FloorToInt(point.x), Mathf.FloorToInt(point.y), 0);

        cellsInPlayerMoveRadius = GetCellsInMoveRadius(playerPos);

        WorldTile worldTile;

        //if we clicked on a tile
        if (tiles.TryGetValue(worldPoint, out worldTile))
        {
            //if we clicked on a sqaure that is within our move distance
            if (cellsInPlayerMoveRadius.Contains(worldTile))
            {
                WorldTile playerTile;
                if (tiles.TryGetValue(playerPos, out playerTile))
                {
                    playerTile.hasPlayer = false;
                    playerTile.entity    = null;
                }

                //lets chart a destination path to the target square
                squaresToTravelTo = PathFinding.FindPath(playerPos, worldPoint);

                //if we can get there, grab the first step
                if (squaresToTravelTo.Count > 0)
                {
                    destinationTile = squaresToTravelTo.Pop();
                }
            }
        }
    }
Beispiel #15
0
    private List <WorldTile> GetCellsInMoveRadius(Vector3Int playerPos)
    {
        List <WorldTile> NeighborEmptyTiles = new List <WorldTile>();

        for (int x = playerPos.x - MoveDistance; x <= playerPos.x + MoveDistance; x++)
        {
            for (int y = playerPos.y - MoveDistance; y <= playerPos.y + MoveDistance; y++)
            {
                var       cellPostion = new Vector3(x, y, 0);
                WorldTile currentCell;
                if (GameTiles.tiles.TryGetValue(cellPostion, out currentCell))
                {
                    if (currentCell.isWalkable)
                    {
                        var pathToSquare = PathFinding.FindPath(playerPos, currentCell.WorldLocation);
                        if (pathToSquare.Count > 0)
                        {
                            if (pathToSquare.Count <= MoveDistance)
                            {
                                NeighborEmptyTiles.Add(currentCell);
                            }
                        }
                    }
                }
            }
        }

        return(NeighborEmptyTiles);
    }
Beispiel #16
0
        public void Obstacle_2()
        {
            int sizeX  = 7;
            int sizeY  = 4;
            int startX = 0;
            int startY = 3;
            int endX   = 6;
            int endY   = 1;

            var mapInfo = new DefaultMapInfo(sizeX, sizeY);

            mapInfo.SetWalkable(3, 1, false);
            mapInfo.SetWalkable(4, 1, false);
            mapInfo.SetWalkable(4, 2, false);

            var pathfinding = new PathFinding(mapInfo);
            var path        = new List <int>();

            pathfinding.FindPath(startX, startY, endX, endY, path);

            string expected =
                "_______\n" +
                "___oo_E\n" +
                "____o#_\n" +
                "S####__";

            string result = MapToString(sizeX, sizeY, startX, startY, endX, endY, path, mapInfo);

            Assert.Equal(expected, result);
        }
Beispiel #17
0
    // Update is called once per frame
    private void Updating()
    {
        if (player)
        {
            if (Vector3.Distance(player.transform.position, transform.position) > 5)
            {
                Vector3 toPosition = player.transform.position;
                Vector3 direction  = toPosition - transform.position;

                Vector3Int ennemiPlayer = new Vector3Int((int)transform.position.x, (int)transform.position.y, (int)transform.position.z);

                float dist = Vector2Int.Distance(new Vector2Int(ennemiPlayer.x, ennemiPlayer.y), new Vector2Int((int)toPosition.x, (int)toPosition.y));

                if (dist < _aggroRange && dist > 1)
                {
                    _offset = ennemiPlayer - new Vector3Int(1, 1, 0) * _aggroRange;

                    int[,] map = TransformTilemap(ennemiPlayer, tlm);

                    Vector3 posPlayer = player.transform.position - _offset;
                    Vector2 pos2D     = posPlayer;

                    map = AddCornerPlayer(pos2D, map);

                    Vector2Int plz = new Vector2Int((int)pos2D.x, (int)pos2D.y);
                    path = PathFinding.FindPath(new Vector2Int(_aggroRange, _aggroRange), plz, map);
                }
            }
        }
    }
Beispiel #18
0
        private void btnGenerateMap_Click(object sender, EventArgs e)
        {
            txtMap.Text = "";

            // Start with a clear map (don't add any obstacles)
            InitializeMap(7, 5, Point.Empty, Point.Empty, true);
            PathFinding       pathFinder = new PathFinding(searchParameters);
            PathFindingResult pathResult = pathFinder.FindPath();

            //txtMap.Text += ShowRoute("The algorithm should find a direct path without obstacles:", path);
            //txtMap.Text += Environment.NewLine;

            //// Now add an obstacle
            //InitializeMap(7, 5, Point.Empty, Point.Empty);
            //AddWallWithGap();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should find a route around the obstacle:", path);
            //txtMap.Text += Environment.NewLine;


            //// Create a barrier between the start and end points
            //InitializeMap(7, 5, Point.Empty, Point.Empty);
            //AddWallWithoutGap();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should not be able to find a route around the barrier:", path);
            //txtMap.Text += Environment.NewLine;


            //// Create a maze with custom start and end points
            //InitializeMap(7, 5, new Point(0, 4), new Point(6, 4));
            //AddWallWithMaze();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the barrier:", path);
            //txtMap.Text += Environment.NewLine;


            //// Create a maze with custom start and end points
            //InitializeMap(7, 5, new Point(0, 4), new Point(4, 2));
            //AddWallWithSpinningMaze();
            //pathFinder = new PathFinding(searchParameters);
            //path = pathFinder.FindPath();
            //txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the barrier:", path);
            //txtMap.Text += Environment.NewLine;


            // Create a larger maze with custom start and end points
            InitializeMap(70, 40, new Point(0, 0), new Point(69, 39), false);
            this.map     = GenerateMap.GenerateRandomMap(this.map, 70, 40, 40);
            pathFinder   = new PathFinding(searchParameters);
            pathResult   = pathFinder.FindPath();
            txtMap.Text += ShowRoute("The algorithm should be able to find a long route around the random blocks:", pathResult.Path);
            txtMap.Text += Environment.NewLine;

            //Console.WriteLine("Press any key to exit...");
            //Console.ReadKey();
        }
 void Update()
 {
     TargetCheck();
     if (proceeding == false)
     {
         OnPath(pathfinding.FindPath(transform.position, target.position));
     }
 }
    void tst()
    {
        List <Vector3Int> path = PathFinding.FindPath(new Vector3Int(0, 0, 0), new Vector3Int(2, 100, 0));

        foreach (var pos in path)
        {
            Tree.Create(new Vector2Int(pos.x, pos.y));
        }
    }
Beispiel #21
0
    //public void goToDirection(int tarX, int tarY, Block[,] theMap) {
    //    pf.theMap = theMap;
    //    pf.setPathFind(currX, currY, tarX, tarY, 12, 9);
    //    path = pf.FindPath();
    //    if (path == null || path.Count == 0) { return; }
    //    target = path[0];
    //    direction = target - this.transform.position;
    //    direction.Normalize();
    //    this.tarX = tarX;
    //    this.tarY = tarY;
    //}

    public void goToDirection(int tarX, int tarY, Block[,] theMap)
    {
        pf.theMap = theMap;
        int currX = (int)Mathf.Round(this.transform.position.x);
        int currY = (int)Mathf.Round(this.transform.position.y);

        pf.setPathFind(currX, currY, tarX, tarY, 12, 9);
        path = pf.FindPath();
    }
Beispiel #22
0
    private void GoToMousePosition()
    {
        Vector3 mouseWorldPosition = GetMouseWorldPosition(Input.mousePosition, Camera.main);

        pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y);
        path = pathfinding.FindPath(this.transform.position, mouseWorldPosition);
        StopCoroutine("FollowPath");
        StartCoroutine("FollowPath");
    }
Beispiel #23
0
        /// <summary>
        /// Handle movement when following target
        /// </summary>
        protected virtual void HandleMovementTarget()
        {
            // get target pos
            Vector3Int targetPosition = Utils.WorldToBlockPosition(Target.position - Vector3.up);

            targetPosition.y = World.GetTopBlockPosition(new Vector2Int(targetPosition.x, targetPosition.z)).y + 1;

            if (targetPosition != lastTargetPosition)
            {
                lastTargetPosition = targetPosition;

                Vector3Int entityPosition = Utils.WorldToBlockPosition(transform.position);

                // try to find path
                Vector3[] path = PathFinding.FindPath(entityPosition, targetPosition);
                if (path == null || path.Length == 0)
                {
                    return;
                }

                pathQueue      = new Queue <Vector3>();
                targetMoveSpot = transform.position;

                // enqueue path nodes
                for (int i = 0; i < path.Length; i++)
                {
                    pathQueue.Enqueue(path[i]);
                }
            }

            // walk to target if path is not null
            if (pathQueue != null)
            {
                if (Vector3.Distance(transform.position, targetMoveSpot) > 0.02f)
                {
                    float x = Mathf.MoveTowards(transform.position.x, targetMoveSpot.x, Speed * Time.fixedDeltaTime);
                    float y = Mathf.MoveTowards(transform.position.y, targetMoveSpot.y, Speed * Time.fixedDeltaTime * 2);
                    float z = Mathf.MoveTowards(transform.position.z, targetMoveSpot.z, Speed * Time.fixedDeltaTime);
                    transform.position = new Vector3(x, y, z);

                    pathNodeTravelTime += Time.fixedDeltaTime;
                }
                else if (pathQueue.Count > 0)
                {
                    targetMoveSpot     = pathQueue.Dequeue();
                    pathNodeTravelTime = 0;
                }

                // TODO: remove this
                // if (pathNodeTravelTime > 2)
                // {
                //     Debug.Log("STUCK");
                //     transform.position = targetMoveSpot;
                // }
            }
        }
Beispiel #24
0
    void FindPath()
    {
        pathFinding.FindPath(unit.position, goal.position);
        if (path == null)
        {
            return;
        }

        unit.position = Vector3.MoveTowards(unit.position, new Vector3(path[0].worldPos.x, 1, path[0].worldPos.z), speed);
    }
Beispiel #25
0
    public void SetTargetPosition(Vector3 targetPosition)
    {
        currentPathIndex = 0;
        pathVectorList   = pathFinding.FindPath(transform.position, targetPosition);

        if (pathVectorList != null && pathVectorList.Count > 1)
        {
            //Debug.Log("removing node from path " + currentPathIndex + " " + pathVectorList[currentPathIndex]);
            pathVectorList.RemoveAt(0);
        }
    }
Beispiel #26
0
    public void InvestigateLocation(Vector2 locationOfInterest)
    {
        CurrentSpeed = InvestigateSpeed;
        PathFinding aStarPathfinding = GetComponentInChildren <PathFinding>();

        nodesToFollow = aStarPathfinding.FindPath(this.transform.position, locationOfInterest);

        CurrentState = ZombieState.Investigate;

        Debug.Log(this.name + " Heard Player");
    }
Beispiel #27
0
    public static List <Tile> GetPath(Tile startTile)
    {
        Vector2 start = startTile.GetPos();

        Tile pathStart = TileController.tileMap[(int)start.y, (int)start.x];
        Tile pathEnd   = TileController.tileMap[(int)end.y, (int)end.x];

        TileController.path = PathFinding.FindPath(pathStart, pathEnd);

        return(new List <Tile>(path));
    }
Beispiel #28
0
    void moveAlongPath()
    {
        //generateDest();

        path = PathFinding.FindPath(rvg, transform.position, dest);
        UnityEngine.Assertions.Assert.IsTrue(dest != null, "dest is null");
        UnityEngine.Assertions.Assert.IsTrue(rvg != null, "rvg is null");
        UnityEngine.Assertions.Assert.IsTrue(transform.position != null, "agent position is null");

        status = AgentStatus.Moving;
        move();
    }
Beispiel #29
0
 public void GoFindPath()
 {
     path = pathFinder.FindPath(player.position, target.position);
     if (path.Length > 0)
     {
         StartCoroutine(OnPathFound(path));
     }
     else
     {
         print("No Path Found");
     }
 }
Beispiel #30
0
    /// <summary>
    /// Updates path (if not found, path is null).
    /// </summary>
    void UpdatePath()
    {
        lastPathCheck = Time.time;
        if ((tankLevel == 0) || (tankLevel == 10))
        {
            path = PathFinding.FindPath(this.transform.position, randomTravelDestinations[Random.Range(0, randomTravelDestinations.Length)]);
        }
        else if ((tankLevel == 1) || (tankLevel == 11))
        {
            if (GameManager.playerInstance.gameObject != null)
            {
                Vector2 target = new Vector2();
                if (GameManager.playerInstance.transform.position.x < 6.5f)
                {
                    target.x = GameManager.playerInstance.transform.position.x + 6.5f;
                    target.y = GameManager.playerInstance.transform.position.y;
                }
                else
                {
                    target.x = 6.5f - (GameManager.playerInstance.transform.position.x - 6.5f);
                    target.y = GameManager.playerInstance.transform.position.y;
                }
                path = PathFinding.FindPath(this.transform.position, target);
            }
            else
            {
                path = null;
            }
        }
        else if ((tankLevel == 2) || (tankLevel == 12))
        {
            path = PathFinding.FindPath(this.transform.position, GameManager.playerInstance.transform.position);
        }
        else if ((tankLevel == 3) || (tankLevel == 13))
        {
            path = PathFinding.FindPath(this.transform.position, new Vector2(6.5f, 0.5f));
        }

        if (path != null)
        {
            currentPathPoint     = 1;
            directionToPathPoint = GetDirectionFromVector(path[1]);
            currentMoveDirection = directionToPathPoint;
            DebugVisualHelper.DrawPath(path);
            checkPathAfter = 10f;
        }
        else
        {
            print("path is null.");
            checkPathAfter          = 3f;
            randomMovementTimeStamp = Time.time;
        }
    }