Exemplo n.º 1
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());
            }
        }
    }