Esempio n. 1
0
    private void CalculateDirectionAndRotationToLook()
    {
        Vector3 foodLocation = (Vector3)blackboard.GetValue("currentFoodLocation");

        directionToFood = Vector3Utilities.GetDirectionXZFromTo(transform.position, foodLocation);
        lookRotation    = Quaternion.LookRotation(directionToFood);
    }
Esempio n. 2
0
        public void LerpThereAndBack_ReturnsCorrectResult(Vector3 first, Vector3 second, float progress, Vector3 expectedResult)
        {
            Vector3 result = Vector3Utilities.LerpThereAndBack(first, second, progress);

            result.Should().Be(expectedResult);
        }
Esempio n. 3
0
 private void calculateDirectionAndRotationToLook(Transform enemy)
 {
     directionToEnemy = Vector3Utilities.GetDirectionXZFromTo(transform.position, enemy.position);
     lookRotation     = Quaternion.LookRotation(directionToEnemy);
 }
Esempio n. 4
0
        void Update()
        {
            if (_animationState == EntityAnimationState.Inactive)
            {
                return;
            }
            if (_animationState == EntityAnimationState.Moving)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action

                Vector3 previousWorldPosition   = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 animationTargetPosition = _gridInfoProvider.GetCellCenterWorld(_animationTargetPosition);
                Vector3 interpolatedPosition
                    = Vector3.Lerp(previousWorldPosition, animationTargetPosition, _timeSinceStartedAnimation / DefaultAnimationDuration);
                transform.position = interpolatedPosition;
                bool finished = _timeSinceStartedAnimation > DefaultAnimationDuration;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
            else if (_animationState == EntityAnimationState.FallingIn)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action

                Vector3 previousWorldPosition   = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 animationTargetPosition = _gridInfoProvider.GetCellCenterWorld(_animationTargetPosition);
                float   progress = _timeSinceStartedAnimation / FallInAnimationDuration;
                Vector3 interpolatedPosition
                    = Vector3.Lerp(previousWorldPosition, animationTargetPosition, progress);
                Vector3    interpolatedScale    = Vector3.Lerp(new Vector3(1, 1, 1), new Vector3(0.5f, 0.5f, 0.5f), progress);
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.Euler(0, 0, 180), progress);
                transform.position   = interpolatedPosition;
                transform.localScale = interpolatedScale;
                transform.rotation   = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    transform.parent           = _entityToBecomeParent.transform;
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                    _entityToBecomeParent      = null;
                }
            }
            else if (_animationState == EntityAnimationState.FallingOut)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action

                Vector3 previousWorldPosition   = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 animationTargetPosition = _gridInfoProvider.GetCellCenterWorld(_animationTargetPosition);
                float   progress = _timeSinceStartedAnimation / FallInAnimationDuration;
                Vector3 interpolatedPosition
                    = Vector3.Lerp(previousWorldPosition, animationTargetPosition, progress);
                Vector3    interpolatedScale    = Vector3.Lerp(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1, 1, 1), progress);
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.identity, progress);
                transform.position   = interpolatedPosition;
                transform.localScale = interpolatedScale;
                transform.rotation   = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    _animationState = EntityAnimationState.Inactive;
                    GetComponent <SpriteRenderer>().sortingOrder -= 1;
                    _timeSinceStartedAnimation = 0f;
                    _entityToBecomeParent      = null;
                }
            }
            else if (_animationState == EntityAnimationState.Bumping)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;
                Vector3 previousWorldPosition = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 middleWayToTarget     = (previousWorldPosition + _gridInfoProvider.GetCellCenterWorld(_animationAffectedPosition)) / 2;
                Vector3 interpolatedPosition
                    = Vector3Utilities.LerpThereAndBack(previousWorldPosition, middleWayToTarget, _timeSinceStartedAnimation / DefaultAnimationDuration);
                transform.position = interpolatedPosition;
                bool finished = _timeSinceStartedAnimation > DefaultAnimationDuration;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
            else if (_animationState == EntityAnimationState.BeingKnockedOut)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action
                float      progress             = _timeSinceStartedAnimation / DefaultAnimationDuration;
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.Euler(0, 0, 180), progress);
                transform.rotation = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
            else if (_animationState == EntityAnimationState.StandingUp)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action
                float      progress             = _timeSinceStartedAnimation / DefaultAnimationDuration;
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.identity, progress);
                transform.rotation = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
        }
 private void CalculateDirectionAndRotationToLook()
 {
     directionToFood = Vector3Utilities.GetDirectionXZFromTo(transform.position, currentTrapPos);
     lookRotation    = Quaternion.LookRotation(directionToFood);
 }
 private void calculateRotation()
 {
     isRotated         = false;
     baseToMeDirection = Vector3Utilities.GetDirectionXZFromTo(baseLocation, transform.position);
     lookRotation      = Quaternion.LookRotation(baseToMeDirection);
 }