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.

52 lines
1.6 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class HandLift : VRTK_InteractableObject
  5. {
  6. [Header("Hand Lift Options", order = 4)]
  7. public float speed = 0.1f;
  8. public Transform handleTop;
  9. public Transform ropeTop;
  10. public Transform ropeBottom;
  11. public GameObject rope;
  12. public GameObject handle;
  13. private bool isMoving = false;
  14. private bool isMovingUp = true;
  15. public override void OnInteractableObjectGrabbed(InteractableObjectEventArgs e)
  16. {
  17. base.OnInteractableObjectGrabbed(e);
  18. isMoving = true;
  19. }
  20. protected override void Update()
  21. {
  22. base.Update();
  23. if (isMoving)
  24. {
  25. Vector3 movePosition = (isMovingUp ? Vector3.up : Vector3.down) * speed * Time.deltaTime;
  26. handle.transform.position += movePosition;
  27. Vector3 scale = rope.transform.localScale;
  28. scale.y = (ropeTop.position.y - handle.transform.position.y) / 2.0f;
  29. Vector3 midpoint = ropeTop.transform.position;
  30. midpoint.y -= scale.y;
  31. rope.transform.localScale = scale;
  32. rope.transform.position = midpoint;
  33. if((!isMovingUp && handle.transform.position.y <= ropeBottom.position.y) ||
  34. (isMovingUp && handle.transform.position.y >= handleTop.position.y))
  35. {
  36. isMoving = false;
  37. isMovingUp = !isMovingUp;
  38. }
  39. }
  40. }
  41. }
  42. }