Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RotationController : MonoBehaviour
  5. {
  6. #region Read-Only Fields
  7. public float RotationPeriod => m_RotationPeriod;
  8. public Vector3 Position => transform.position;
  9. public Vector3 RotationAxis => m_RotationAxis;
  10. public float CorrelusStrength => m_correlusStrength;
  11. #endregion Read-Only Fields
  12. [SerializeField]
  13. private float m_RotationPeriod;
  14. [SerializeField]
  15. private Vector3 m_RotationAxis = Vector3.forward;
  16. [SerializeField]
  17. private float m_correlusStrength = 100;
  18. public Vector3 getDownDirection(Vector3 objectPosition, bool normalized = true)
  19. {
  20. if (normalized)
  21. return Vector3.ProjectOnPlane((objectPosition - transform.position), m_RotationAxis).normalized;
  22. else
  23. return Vector3.ProjectOnPlane((objectPosition - transform.position), m_RotationAxis);
  24. }
  25. public Vector3 getPerpendicularDirection(Vector3 objectPosition)
  26. {
  27. return Vector3.Cross(RotationAxis, getDownDirection(objectPosition)).normalized;
  28. }
  29. private void FixedUpdate()
  30. {
  31. //transform.Rotate(m_RotationAxis, 360 / m_RotationPeriod * Time.fixedDeltaTime);
  32. }
  33. }