RotateJoint.cs 746 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RotateJoint : MonoBehaviour
  5. {
  6. Rigidbody m_Rigidbody;
  7. Vector3 m_EulerAngleVelocity;
  8. float timer = 5;
  9. float defaultTimer = 5;
  10. void Start()
  11. {
  12. m_EulerAngleVelocity = new Vector3(20,20,20);
  13. m_Rigidbody = GetComponent<Rigidbody>();
  14. }
  15. void FixedUpdate()
  16. {
  17. timer -= Time.deltaTime;
  18. if(timer < 0)
  19. {
  20. m_EulerAngleVelocity = -m_EulerAngleVelocity;
  21. timer = defaultTimer;
  22. }
  23. Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.deltaTime);
  24. m_Rigidbody.MoveRotation(m_Rigidbody.rotation * deltaRotation);
  25. }
  26. }