RotateRigidbody.cs 707 B

1234567891011121314151617181920212223242526272829
  1. // Shatter Toolkit
  2. // Copyright 2015 Gustav Olsson
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace ShatterToolkit.Examples
  6. {
  7. [RequireComponent(typeof(Rigidbody))]
  8. public class RotateRigidbody : MonoBehaviour
  9. {
  10. public Vector3 axis = Vector3.up;
  11. public float angularVelocity = 7.0f;
  12. protected Rigidbody rb;
  13. public void Start()
  14. {
  15. rb = GetComponent<Rigidbody>();
  16. }
  17. public void FixedUpdate()
  18. {
  19. Quaternion deltaRotation = Quaternion.AngleAxis(angularVelocity * Time.fixedDeltaTime, axis);
  20. rb.MoveRotation(rb.rotation * deltaRotation);
  21. }
  22. }
  23. }