Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. THIS ONE WORKS
  2.  
  3. [Command]
  4. private void CmdCheckForJump(InputData data)
  5. {
  6. if (touchingGround) afterJumpTimeCounter = walkBufferOnPlatforms;
  7. if (data.inputW) beforeJumpTimeCounter = walkBufferOnPlatforms;
  8.  
  9. if (((data.inputW && (touchingGround || afterJumpTimeCounter > 0)) || (beforeJumpTimeCounter > 0 && touchingGround)) && !isJumping)
  10. {
  11. CmdChangeUTorsoRGVelocity(true, new Vector2(uTorsoRG.velocity.x, magnitudeUpBoost));
  12. isJumping = true;
  13. jumpTimeCounter = jumpTime;
  14. }
  15.  
  16. if (data.inputW && isJumping)
  17. {
  18. if (jumpTimeCounter > 0)
  19. {
  20. CmdChangeUTorsoRGVelocity(false, new Vector2(0, magnitudeUp * Mathf.Cos((jumpTime - jumpTimeCounter) / jumpTime)));
  21. }
  22. else isJumping = false;
  23. }
  24. else isJumping = false;
  25. }
  26.  
  27. void UseInputData(InputData data)
  28. {
  29. bool walkA = false, walkD = false, calledSlide = false, calledFlip = false, pressedAOrD = false, pressedS = false;
  30.  
  31. float groundRot = RaycastDownReturnHit().collider.gameObject.transform.eulerAngles.z;
  32. float downRaycast = RaycastDown();
  33.  
  34. bool walkRaycast = RaycastToWalk();
  35.  
  36. if ((data.inputQ || data.inputE))
  37. {
  38. int dir = data.inputQ ? 1 : -1;
  39. flipActionScript.CmdFlip(dir, !isFlipping, walkRaycast);
  40. calledFlip = true;
  41. }
  42.  
  43. CmdCheckForJump(data);
  44.  
  45. if (data.inputS)
  46. {
  47. if ((data.inputA || data.inputD) && !isFlipping)
  48. {
  49. if (((uTorsoRG.velocity.magnitude > minVeloSlide && isSliding) || (!isSliding && !holdingAOrD) || (slideFrames < minSlideFrames)) && !isUpFromSlide)
  50. {
  51. int dir = data.inputD ? 1 : -1;
  52. int groundRotMultiplier = (downRaycast < heightToMatchGroundAngleWithAnim) ? 1 : 0;
  53. slideActionScript.CmdSlide(dir, isSliding, true, groundRot * groundRotMultiplier);
  54. calledSlide = true;
  55. }
  56. if (isSliding && uTorsoRG.velocity.magnitude < minVeloSlide && slideFrames > minSlideFrames) isUpFromSlide = true;
  57. pressedAOrD = true;
  58. }
  59. else
  60. {
  61. CmdAddForceToUTorsoRG(Vector3.down * magnitudeDown);
  62. pressedS = true;
  63. }
  64. }
  65. else
  66. {
  67. if (data.inputA)
  68. {
  69. CmdAddForceToUTorsoRG(Vector3.right * -1 * magnitudeSide);
  70. walkA = true;
  71. }
  72.  
  73. if (data.inputD)
  74. {
  75. CmdAddForceToUTorsoRG(Vector3.right * magnitudeSide);
  76. walkD = true;
  77. }
  78. }
  79.  
  80. if (!isSliding && !isFlipping && !isSpeedDescending)
  81. {
  82. if (walkRaycast)
  83. {
  84. RaycastHit2D groundHit = RaycastDownReturnHit();
  85. if (groundHit.collider.transform.eulerAngles.z < maxAngleForWalk || groundHit.collider.transform.eulerAngles.z > 360 - maxAngleForWalk)
  86. {
  87. if (walkA) GetComponent<WalkAction>().CmdWalk(-1, groundRot);
  88. else if (walkD) GetComponent<WalkAction>().CmdWalk(1, groundRot);
  89. }
  90. }
  91. else
  92. {
  93. RaycastHit2D veloRaycast = VeloRaycast();
  94. if (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude > maxTimeTORemoveResistance) CmdSetMusclesToResist(1);
  95. else
  96. {
  97. float percentage = (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude) / maxTimeTORemoveResistance;
  98. CmdSetMusclesToResist(percentage);
  99. }
  100. }
  101. }
  102.  
  103. if ((isWalking && !walkA && !walkD) || (isSliding && !calledSlide))
  104. {
  105. StartCoroutine(SlowDown());
  106. }
  107.  
  108. isSliding = calledSlide;
  109. isFlipping = calledFlip;
  110. holdingAOrD = pressedAOrD;
  111. isWalking = walkA || walkD;
  112. slideFrames = isSliding || holdingAOrD ? slideFrames + 1 : 0;
  113. isUpFromSlide = holdingAOrD && isUpFromSlide;
  114. isSpeedDescending = pressedS;
  115. jumpTimeCounter++;
  116. beforeJumpTimeCounter--;
  117. afterJumpTimeCounter--;
  118.  
  119. CmdClampVelocity();
  120.  
  121. CmdActivateMuscles();
  122. }
  123.  
  124.  
  125. THIS ONE DOESNT
  126.  
  127.  
  128. void UseInputData(InputData data)
  129. {
  130. bool walkA = false, walkD = false, calledSlide = false, calledFlip = false, pressedAOrD = false, pressedS = false;
  131.  
  132. float groundRot = RaycastDownReturnHit().collider.gameObject.transform.eulerAngles.z;
  133. float downRaycast = RaycastDown();
  134.  
  135. bool walkRaycast = RaycastToWalk();
  136.  
  137. if ((data.inputQ || data.inputE))
  138. {
  139. int dir = data.inputQ ? 1 : -1;
  140. flipActionScript.CmdFlip(dir, !isFlipping, walkRaycast);
  141. calledFlip = true;
  142. }
  143.  
  144. if (touchingGround) afterJumpTimeCounter = walkBufferOnPlatforms;
  145. if (data.inputW) beforeJumpTimeCounter = walkBufferOnPlatforms;
  146.  
  147. if (((data.inputW && (touchingGround || afterJumpTimeCounter > 0)) || (beforeJumpTimeCounter > 0 && touchingGround)) && !isJumping)
  148. {
  149. CmdChangeUTorsoRGVelocity(true, new Vector2(uTorsoRG.velocity.x, magnitudeUpBoost));
  150. isJumping = true;
  151. jumpTimeCounter = jumpTime;
  152. }
  153.  
  154. if (data.inputW && isJumping)
  155. {
  156. if (jumpTimeCounter > 0)
  157. {
  158. CmdChangeUTorsoRGVelocity(false, new Vector2(0, magnitudeUp * Mathf.Cos((jumpTime - jumpTimeCounter) / jumpTime)));
  159. }
  160. else isJumping = false;
  161. }
  162. else isJumping = false;
  163.  
  164. if (data.inputS)
  165. {
  166. if ((data.inputA || data.inputD) && !isFlipping)
  167. {
  168. if (((uTorsoRG.velocity.magnitude > minVeloSlide && isSliding) || (!isSliding && !holdingAOrD) || (slideFrames < minSlideFrames)) && !isUpFromSlide)
  169. {
  170. int dir = data.inputD ? 1 : -1;
  171. int groundRotMultiplier = (downRaycast < heightToMatchGroundAngleWithAnim) ? 1 : 0;
  172. slideActionScript.CmdSlide(dir, isSliding, true, groundRot * groundRotMultiplier);
  173. calledSlide = true;
  174. }
  175. if (isSliding && uTorsoRG.velocity.magnitude < minVeloSlide && slideFrames > minSlideFrames) isUpFromSlide = true;
  176. pressedAOrD = true;
  177. }
  178. else
  179. {
  180. CmdAddForceToUTorsoRG(Vector3.down * magnitudeDown);
  181. pressedS = true;
  182. }
  183. }
  184. else
  185. {
  186. if (data.inputA)
  187. {
  188. CmdAddForceToUTorsoRG(Vector3.right * -1 * magnitudeSide);
  189. walkA = true;
  190. }
  191.  
  192. if (data.inputD)
  193. {
  194. CmdAddForceToUTorsoRG(Vector3.right * magnitudeSide);
  195. walkD = true;
  196. }
  197. }
  198.  
  199. if (!isSliding && !isFlipping && !isSpeedDescending)
  200. {
  201. if (walkRaycast)
  202. {
  203. RaycastHit2D groundHit = RaycastDownReturnHit();
  204. if (groundHit.collider.transform.eulerAngles.z < maxAngleForWalk || groundHit.collider.transform.eulerAngles.z > 360 - maxAngleForWalk)
  205. {
  206. if (walkA) GetComponent<WalkAction>().CmdWalk(-1, groundRot);
  207. else if (walkD) GetComponent<WalkAction>().CmdWalk(1, groundRot);
  208. }
  209. }
  210. else
  211. {
  212. RaycastHit2D veloRaycast = VeloRaycast();
  213. if (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude > maxTimeTORemoveResistance) CmdSetMusclesToResist(1);
  214. else
  215. {
  216. float percentage = (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude) / maxTimeTORemoveResistance;
  217. CmdSetMusclesToResist(percentage);
  218. }
  219. }
  220. }
  221.  
  222. if ((isWalking && !walkA && !walkD) || (isSliding && !calledSlide))
  223. {
  224. StartCoroutine(SlowDown());
  225. }
  226.  
  227. isSliding = calledSlide;
  228. isFlipping = calledFlip;
  229. holdingAOrD = pressedAOrD;
  230. isWalking = walkA || walkD;
  231. slideFrames = isSliding || holdingAOrD ? slideFrames + 1 : 0;
  232. isUpFromSlide = holdingAOrD && isUpFromSlide;
  233. isSpeedDescending = pressedS;
  234. jumpTimeCounter++;
  235. beforeJumpTimeCounter--;
  236. afterJumpTimeCounter--;
  237.  
  238. CmdClampVelocity();
  239.  
  240. CmdActivateMuscles();
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement