Exemplo n.º 1
0
    IEnumerator Move(List <PathNode> path)
    {
        var linkedList = new LinkedList <PathNode>(path);

        foreach (var node in linkedList)
        {
            var next = linkedList.Find(node).Next?.Value;
            if (next != null)
            {
                var offset = new Vector2Int(next.x, next.z) - new Vector2Int(node.x, node.z);
                Entity.Direction = PathFindingManager.GetDirectionForOffset(offset);
            }

            MoveToIE = StartCoroutine(MoveTo(node));
            yield return(MoveToIE);
        }

        yield return(OnWalkEnd());
    }
Exemplo n.º 2
0
    private void Update()
    {
        if (isWalking && !nodes.IsEmpty())
        {
            bool isEnd = false;
            while (_tick <= Core.Tick)
            {
                var current = nodes[nodeIndex];
                if (nodeIndex == nodes.Count - 1)
                {
                    isEnd = true;
                    break;
                }
                var next       = nodes[nodeIndex + 1];
                var isDiagonal = PathFindingManager.IsDiagonal(next, current);
                lastSpeed = (ushort)(isDiagonal ? Entity.GetBaseStatus().walkSpeed * 14 / 10 : Entity.GetBaseStatus().walkSpeed); //Diagonal walking is slower
                _tick    += lastSpeed;
                nodeIndex++;
            }

            var   currentNode = nodeIndex == 0 ? lastPosition : nodes[nodeIndex - 1];
            var   nextNode    = nodes[nodeIndex];
            var   direction   = nextNode - currentNode;
            float timeDelta   = 1 - Math.Max(_tick - Core.Tick, 0f) / lastSpeed;

            transform.position = currentNode + direction * timeDelta;
            Entity.Direction   = PathFindingManager.GetDirectionForOffset(nextNode, currentNode);

            if (isEnd)
            {
                isWalking = false;
                nodes.Clear();

                StartCoroutine(OnWalkEnd());
            }
        }
    }
Exemplo n.º 3
0
    public void LookTo(Vector3 position)
    {
        var offset = new Vector2Int((int)position.x, (int)position.z) - new Vector2Int((int)transform.position.x, (int)transform.position.z);

        Direction = PathFindingManager.GetDirectionForOffset(offset);
    }