Exemplo n.º 1
0
        public void MoveTo(NavMeshGridNode node)
        {
            BuildPath(node);

            if (_currentPath.IsFound && _currentPath.ResultPathNodes.Count > 0)
            {
                StartMoving();
            }
        }
Exemplo n.º 2
0
        private NavMeshGridNode FindClosestNode()
        {
            float           minDistance = Mathf.Infinity;
            NavMeshGridNode closestNode = null;

            foreach (var node in _navMeshGrid.Nodes)
            {
                var currentDistance = Vector2.Distance(transform.position, node.Position);

                if (currentDistance < minDistance)
                {
                    minDistance = currentDistance;
                    closestNode = node;
                }
            }

            return(closestNode);
        }
Exemplo n.º 3
0
        public void Update()
        {
            var horizontalInput = Input.GetAxisRaw("Horizontal");
            var verticalInput   = Input.GetAxisRaw("Vertical");

            if (horizontalInput != 0 || verticalInput != 0)
            {
                var positionDelta = new Vector2(horizontalInput, verticalInput).normalized * 0.08f;
                transform.position += (Vector3)positionDelta;

                var lastNodeIndex = _closestNode.Index;
                _closestNode = FindClosestNode();

                if (lastNodeIndex != _closestNode.Index)
                {
                    _testUnit.MoveTo(_closestNode);
                }
            }
        }
Exemplo n.º 4
0
 private void OnEnable()
 {
     _closestNode = FindClosestNode();
 }
Exemplo n.º 5
0
 public PathNode(NavMeshGridNode node, int cost)
 {
     Node = node;
     Cost = cost;
 }