Advertisement
Guest User

AOTVR ShootAndReel

a guest
May 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. public void Shoot()
  2. {
  3. if (EnableShoot && !fired)
  4. {
  5. fired = true;
  6. }
  7. else if(EnableShoot && fired && hooked)
  8. {
  9. fired = false;
  10. hooked = false;
  11. ReturnHook();
  12. }
  13. }
  14.  
  15. RaycastHit hit;
  16. private void Update()
  17. {
  18. Vector3 fwd = RaycastStart.transform.TransformDirection(Vector3.forward);
  19. Physics.Raycast(RaycastStart.transform.position, fwd, out hit, RaycastDistance);
  20. Debug.DrawRay(RaycastStart.transform.position, fwd, Color.red, RaycastDistance);
  21.  
  22. EndPoint.transform.position = hit.point;
  23.  
  24. if (fired && !hooked)
  25. {
  26. hook.transform.position = Vector3.MoveTowards(hook.transform.position, EndPoint.transform.position, hookTravelSpeed);
  27.  
  28.  
  29. if (settings.ViveSDK)
  30. {
  31. currentDistance = Vector3.Distance(ViveSDK.transform.position, hook.transform.position);
  32. }
  33. if (settings.OculusSDK)
  34. {
  35. currentDistance = Vector3.Distance(OculusSDK.transform.position, hook.transform.position);
  36. }
  37.  
  38. if(currentDistance >= maxDistance)
  39. {
  40. ReturnHook();
  41. }
  42. }
  43.  
  44. if (Reel)
  45. {
  46.  
  47.  
  48. if (settings.ViveSDK)
  49. {
  50. ViveRigid.AddForce((hook.transform.position - ViveSDK.transform.position).normalized * playerTravelSpeed);
  51.  
  52.  
  53. distanceToHook = Vector3.Distance(ViveSDK.transform.position, hook.transform.position);
  54. }
  55. if (settings.OculusSDK)
  56. {
  57. OculusRigid.AddForce((hook.transform.position - OculusSDK.transform.position).normalized * playerTravelSpeed);
  58.  
  59. distanceToHook = Vector3.Distance(OculusSDK.transform.position, hook.transform.position);
  60. }
  61.  
  62. if(distanceToHook < DistanceToStick && Reel)
  63. {
  64. Stick = true;
  65.  
  66.  
  67. }
  68. else
  69. {
  70. Stick = false;
  71.  
  72.  
  73. }
  74. if(currentDistance > FarthestDistance)
  75. {
  76. ReturnHook();
  77. }
  78.  
  79. }
  80.  
  81. if (hooked)
  82. {
  83. hook.transform.parent = hookedObj.transform;
  84. }
  85. if (!hooked){
  86. hook.transform.parent = hookHolder.transform;
  87. }
  88.  
  89. }
  90. public void ReturnHook()
  91. {
  92. hook.transform.position = hookHolder.transform.position;
  93. fired = false;
  94. hooked = false;
  95. }
  96.  
  97. public void ReelIn()
  98. {
  99. if (hooked)
  100. {
  101.  
  102. Reel = true;
  103. }
  104. }
  105. public void StopReel()
  106. {
  107. if (hooked)
  108. {
  109. Reel = false;
  110. }
  111. }
  112. public void StickOn()
  113. {
  114. if (Stick)
  115. {
  116. if (StickOnMore)
  117. {
  118. StickOnMore = false;
  119.  
  120. OculusRigid.constraints = RigidbodyConstraints.None;
  121. OculusRigid.constraints = RigidbodyConstraints.FreezeRotation;
  122. ViveRigid.constraints = RigidbodyConstraints.None;
  123. ViveRigid.constraints = RigidbodyConstraints.FreezeRotation;
  124. }
  125. else if (!StickOnMore)
  126. {
  127. StickOnMore = true;
  128. Reel = false;
  129. Debug.Log("StickToObject");
  130. if (settings.ViveSDK)
  131. {
  132. ViveRigid.constraints = RigidbodyConstraints.FreezePosition;
  133.  
  134. }
  135. if (settings.OculusSDK)
  136. {
  137. OculusRigid.constraints = RigidbodyConstraints.FreezePosition;
  138. }
  139. }
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement