Ejemplo n.º 1
0
    // -------------------------- Unit Movement ---------------------------------

    private void ManageUnitMovement()
    {
        // Lerp - transition from-tile-to-tile.
        if (IsWalking)
        {
            if (HasReachedNextTile())
            {
                MoveToNextTile();
            }

            // controls the speed of each tile transition.
            _currentLerpTime += Time.deltaTime;
            if (_currentLerpTime == LerpDuration)
            {
                _currentLerpTime = LerpDuration;
            }
            // percentage = [0,1] where 0 means "at startPosition" and 1 means "reached lerp endPosition". Anything in between means "still moving".
            float percentage = _currentLerpTime / LerpDuration;
            // Smoothly animate towards the correct map tile.
            transform.position = Vector2.Lerp(transform.position, Map.TileCoordToWorldCoord(TileX, TileY), percentage);                 //25f * Time.deltaTime

            if (HasReachedFinalDestination())
            {
                IsWalking = false;
                // Teleport us to our correct "current" position, in case we
                // haven't finished the animation yet.
                transform.position = Map.TileCoordToWorldCoord(TileX, TileY);
                // update state machine.
                _unitState.UnitSelected2UnitArrived();
            }
        }
    }