Vector3Smoothed.cs 917 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License. See LICENSE in the project root for license information.
  3. using System;
  4. using UnityEngine;
  5. namespace Microsoft.MixedReality.Toolkit.Utilities
  6. {
  7. [Serializable]
  8. public struct Vector3Smoothed
  9. {
  10. public Vector3 Current { get; set; }
  11. public Vector3 Goal { get; set; }
  12. public float SmoothTime { get; set; }
  13. public Vector3Smoothed(Vector3 value, float smoothingTime) : this()
  14. {
  15. Current = value;
  16. Goal = value;
  17. SmoothTime = smoothingTime;
  18. }
  19. public void Update(float deltaTime)
  20. {
  21. Current = Vector3.Lerp(Current, Goal, (Math.Abs(SmoothTime) < Mathf.Epsilon) ? 1.0f : deltaTime / SmoothTime);
  22. }
  23. public void SetGoal(Vector3 newGoal)
  24. {
  25. Goal = newGoal;
  26. }
  27. }
  28. }