protected void FixedUpdate()
        {
            if (_moving)
            {
                if (Math.Abs(MoveDuration) < 0.01f)
                {
                    _moving = false;

                    gameObject.transform.position    = _finalPosition;
                    gameObject.transform.eulerAngles = _finalRotation;

                    return;
                }

                var deltaTime = GetDeltaTime();

                _currentDuration += deltaTime;

                var lerpPoint = Mathf.Clamp(_currentDuration / MoveDuration, 0.0f, 1.0f);

                gameObject.transform.position =
                    VectorFunctions.LerpVector(_initialLerpPosition, _finalPosition, lerpPoint);

                gameObject.transform.eulerAngles =
                    VectorFunctions.LerpVector(_initialLerpRotation, _finalRotation, lerpPoint);

                if (_currentDuration > MoveDuration)
                {
                    _moving          = false;
                    _currentDuration = 0.0f;
                }
            }
        }
        public void Update_Trigger_LerpsToExpectedValue()
        {
            const float expectedLerp = 0.5f;

            BeginTriggerResponse();
            _triggerResponse.TestUpdate(_triggerResponse.MoveDuration * expectedLerp);

            Assert.AreEqual(VectorFunctions.LerpVector(Vector3.zero, _triggerResponse.FinalPosition.transform.position, expectedLerp), _triggerResponse.gameObject.transform.position);
            Assert.AreEqual(VectorFunctions.LerpVector(Vector3.zero, _triggerResponse.FinalPosition.transform.eulerAngles, expectedLerp), _triggerResponse.gameObject.transform.eulerAngles);
        }
示例#3
0
        public void LerpVector_ClampsAt0()
        {
            var firstVector  = new Vector3(-2.0f, 101.1f, 30.0f);
            var secondVector = new Vector3(12.0f, -30.0f, 27.0f);

            Assert.AreEqual
                (new Vector3
                (
                    Mathf.Lerp(firstVector.x, secondVector.x, 0.0f),
                    Mathf.Lerp(firstVector.y, secondVector.y, 0.0f),
                    Mathf.Lerp(firstVector.z, secondVector.z, 0.0f)
                ),
                VectorFunctions.LerpVector(firstVector, secondVector, -1.2f)
                );
        }
示例#4
0
        public void LerpVector_ReturnsLerpedVector()
        {
            var firstVector  = new Vector3(-2.0f, 101.1f, 30.0f);
            var secondVector = new Vector3(12.0f, -30.0f, 27.0f);

            const float lerpPoint = 0.7f;

            Assert.AreEqual
                (new Vector3
                (
                    Mathf.Lerp(firstVector.x, secondVector.x, lerpPoint),
                    Mathf.Lerp(firstVector.y, secondVector.y, lerpPoint),
                    Mathf.Lerp(firstVector.z, secondVector.z, lerpPoint)
                ),
                VectorFunctions.LerpVector(firstVector, secondVector, lerpPoint)
                );
        }