UnityEngine.Vector2.Lerp C# (CSharp) Method

Lerp() public static method

public static Lerp ( Vector2 from, Vector2 to, float t ) : Vector2
from Vector2
to Vector2
t float
return Vector2
		public static Vector2 Lerp(Vector2 from, Vector2 to, float t)
		{
			if (t < 0f)
				return from;
			if (t > 1f)
				return to;
			return (to - from) * t + from;
		}

Usage Example

Esempio n. 1
0
        protected virtual void CalculateNextRotation(float slowdown, out Quaternion nextRotation)
        {
            if (lastDeltaTime > 0.00001f)
            {
                Vector2 desiredRotationDirection;
                if (rvoController != null && rvoController.enabled)
                {
                    // When using local avoidance, use the actual velocity we are moving with if that velocity
                    // is high enough, otherwise fall back to the velocity that we want to move with (velocity2D).
                    // The local avoidance velocity can be very jittery when the character is close to standing still
                    // as it constantly makes small corrections. We do not want the rotation of the character to be jittery.
                    var actualVelocity = lastDeltaPosition / lastDeltaTime;
                    desiredRotationDirection = Vector2.Lerp(velocity2D, actualVelocity, 4 * actualVelocity.magnitude / (maxSpeed + 0.0001f));
                }
                else
                {
                    desiredRotationDirection = velocity2D;
                }

                // Rotate towards the direction we are moving in.
                // Don't rotate when we are very close to the target.
                var currentRotationSpeed = rotationSpeed * Mathf.Max(0, (slowdown - 0.3f) / 0.7f);
                nextRotation = SimulateRotationTowards(desiredRotationDirection, currentRotationSpeed * lastDeltaTime);
            }
            else
            {
                // TODO: simulatedRotation
                nextRotation = rotation;
            }
        }
All Usage Examples Of UnityEngine.Vector2::Lerp