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.

50 lines
2.5 KiB

  1. // Rotate Object Control Action|ObjectControlActions|25020
  2. namespace VRTK
  3. {
  4. using UnityEngine;
  5. /// <summary>
  6. /// Provides the ability to rotate a GameObject through the world `y` axis in the scene by updating the Transform rotation when the corresponding Object Control axis changes.
  7. /// </summary>
  8. /// <remarks>
  9. /// > The effect is a smooth rotation to simulate turning.
  10. ///
  11. /// **Required Components:**
  12. /// * `VRTK_ObjectControl` - The Object Control script to listen for the axis changes on.
  13. ///
  14. /// **Script Usage:**
  15. /// * Place the `VRTK_RotateObjectControlAction` script on any active scene GameObject.
  16. /// * Link the required Object Control script to the `Object Control Script` parameter of this script.
  17. /// * Set the `Listen On Axis Change` parameter on this script to the axis change to affect with this movement type.
  18. /// </remarks>
  19. /// <example>
  20. /// `VRTK/Examples/017_CameraRig_TouchpadWalking` has a collection of walls and slopes that can be traversed by the user with the touchpad. There is also an area that can only be traversed if the user is crouching.
  21. ///
  22. /// To enable the Rotate Object Control Action, ensure one of the `TouchpadControlOptions` children (located under the Controller script alias) has the `Rotate` control script active.
  23. /// </example>
  24. [AddComponentMenu("VRTK/Scripts/Locomotion/Object Control Actions/VRTK_RotateObjectControlAction")]
  25. public class VRTK_RotateObjectControlAction : VRTK_BaseObjectControlAction
  26. {
  27. [Tooltip("The maximum speed the controlled object can be rotated based on the position of the axis.")]
  28. public float maximumRotationSpeed = 3f;
  29. [Tooltip("The rotation multiplier to be applied when the modifier button is pressed.")]
  30. public float rotationMultiplier = 1.5f;
  31. protected override void Process(GameObject controlledGameObject, Transform directionDevice, Vector3 axisDirection, float axis, float deadzone, bool currentlyFalling, bool modifierActive)
  32. {
  33. CheckForPlayerBeforeRotation(controlledGameObject);
  34. float angle = Rotate(axis, modifierActive);
  35. if (angle != 0f)
  36. {
  37. RotateAroundPlayer(controlledGameObject, angle);
  38. }
  39. CheckForPlayerAfterRotation(controlledGameObject);
  40. }
  41. protected virtual float Rotate(float axis, bool modifierActive)
  42. {
  43. return axis * maximumRotationSpeed * Time.deltaTime * (modifierActive ? rotationMultiplier : 1) * 10;
  44. }
  45. }
  46. }