Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- THIS ONE WORKS
- [Command]
- private void CmdCheckForJump(InputData data)
- {
- if (touchingGround) afterJumpTimeCounter = walkBufferOnPlatforms;
- if (data.inputW) beforeJumpTimeCounter = walkBufferOnPlatforms;
- if (((data.inputW && (touchingGround || afterJumpTimeCounter > 0)) || (beforeJumpTimeCounter > 0 && touchingGround)) && !isJumping)
- {
- CmdChangeUTorsoRGVelocity(true, new Vector2(uTorsoRG.velocity.x, magnitudeUpBoost));
- isJumping = true;
- jumpTimeCounter = jumpTime;
- }
- if (data.inputW && isJumping)
- {
- if (jumpTimeCounter > 0)
- {
- CmdChangeUTorsoRGVelocity(false, new Vector2(0, magnitudeUp * Mathf.Cos((jumpTime - jumpTimeCounter) / jumpTime)));
- }
- else isJumping = false;
- }
- else isJumping = false;
- }
- void UseInputData(InputData data)
- {
- bool walkA = false, walkD = false, calledSlide = false, calledFlip = false, pressedAOrD = false, pressedS = false;
- float groundRot = RaycastDownReturnHit().collider.gameObject.transform.eulerAngles.z;
- float downRaycast = RaycastDown();
- bool walkRaycast = RaycastToWalk();
- if ((data.inputQ || data.inputE))
- {
- int dir = data.inputQ ? 1 : -1;
- flipActionScript.CmdFlip(dir, !isFlipping, walkRaycast);
- calledFlip = true;
- }
- CmdCheckForJump(data);
- if (data.inputS)
- {
- if ((data.inputA || data.inputD) && !isFlipping)
- {
- if (((uTorsoRG.velocity.magnitude > minVeloSlide && isSliding) || (!isSliding && !holdingAOrD) || (slideFrames < minSlideFrames)) && !isUpFromSlide)
- {
- int dir = data.inputD ? 1 : -1;
- int groundRotMultiplier = (downRaycast < heightToMatchGroundAngleWithAnim) ? 1 : 0;
- slideActionScript.CmdSlide(dir, isSliding, true, groundRot * groundRotMultiplier);
- calledSlide = true;
- }
- if (isSliding && uTorsoRG.velocity.magnitude < minVeloSlide && slideFrames > minSlideFrames) isUpFromSlide = true;
- pressedAOrD = true;
- }
- else
- {
- CmdAddForceToUTorsoRG(Vector3.down * magnitudeDown);
- pressedS = true;
- }
- }
- else
- {
- if (data.inputA)
- {
- CmdAddForceToUTorsoRG(Vector3.right * -1 * magnitudeSide);
- walkA = true;
- }
- if (data.inputD)
- {
- CmdAddForceToUTorsoRG(Vector3.right * magnitudeSide);
- walkD = true;
- }
- }
- if (!isSliding && !isFlipping && !isSpeedDescending)
- {
- if (walkRaycast)
- {
- RaycastHit2D groundHit = RaycastDownReturnHit();
- if (groundHit.collider.transform.eulerAngles.z < maxAngleForWalk || groundHit.collider.transform.eulerAngles.z > 360 - maxAngleForWalk)
- {
- if (walkA) GetComponent<WalkAction>().CmdWalk(-1, groundRot);
- else if (walkD) GetComponent<WalkAction>().CmdWalk(1, groundRot);
- }
- }
- else
- {
- RaycastHit2D veloRaycast = VeloRaycast();
- if (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude > maxTimeTORemoveResistance) CmdSetMusclesToResist(1);
- else
- {
- float percentage = (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude) / maxTimeTORemoveResistance;
- CmdSetMusclesToResist(percentage);
- }
- }
- }
- if ((isWalking && !walkA && !walkD) || (isSliding && !calledSlide))
- {
- StartCoroutine(SlowDown());
- }
- isSliding = calledSlide;
- isFlipping = calledFlip;
- holdingAOrD = pressedAOrD;
- isWalking = walkA || walkD;
- slideFrames = isSliding || holdingAOrD ? slideFrames + 1 : 0;
- isUpFromSlide = holdingAOrD && isUpFromSlide;
- isSpeedDescending = pressedS;
- jumpTimeCounter++;
- beforeJumpTimeCounter--;
- afterJumpTimeCounter--;
- CmdClampVelocity();
- CmdActivateMuscles();
- }
- THIS ONE DOESNT
- void UseInputData(InputData data)
- {
- bool walkA = false, walkD = false, calledSlide = false, calledFlip = false, pressedAOrD = false, pressedS = false;
- float groundRot = RaycastDownReturnHit().collider.gameObject.transform.eulerAngles.z;
- float downRaycast = RaycastDown();
- bool walkRaycast = RaycastToWalk();
- if ((data.inputQ || data.inputE))
- {
- int dir = data.inputQ ? 1 : -1;
- flipActionScript.CmdFlip(dir, !isFlipping, walkRaycast);
- calledFlip = true;
- }
- if (touchingGround) afterJumpTimeCounter = walkBufferOnPlatforms;
- if (data.inputW) beforeJumpTimeCounter = walkBufferOnPlatforms;
- if (((data.inputW && (touchingGround || afterJumpTimeCounter > 0)) || (beforeJumpTimeCounter > 0 && touchingGround)) && !isJumping)
- {
- CmdChangeUTorsoRGVelocity(true, new Vector2(uTorsoRG.velocity.x, magnitudeUpBoost));
- isJumping = true;
- jumpTimeCounter = jumpTime;
- }
- if (data.inputW && isJumping)
- {
- if (jumpTimeCounter > 0)
- {
- CmdChangeUTorsoRGVelocity(false, new Vector2(0, magnitudeUp * Mathf.Cos((jumpTime - jumpTimeCounter) / jumpTime)));
- }
- else isJumping = false;
- }
- else isJumping = false;
- if (data.inputS)
- {
- if ((data.inputA || data.inputD) && !isFlipping)
- {
- if (((uTorsoRG.velocity.magnitude > minVeloSlide && isSliding) || (!isSliding && !holdingAOrD) || (slideFrames < minSlideFrames)) && !isUpFromSlide)
- {
- int dir = data.inputD ? 1 : -1;
- int groundRotMultiplier = (downRaycast < heightToMatchGroundAngleWithAnim) ? 1 : 0;
- slideActionScript.CmdSlide(dir, isSliding, true, groundRot * groundRotMultiplier);
- calledSlide = true;
- }
- if (isSliding && uTorsoRG.velocity.magnitude < minVeloSlide && slideFrames > minSlideFrames) isUpFromSlide = true;
- pressedAOrD = true;
- }
- else
- {
- CmdAddForceToUTorsoRG(Vector3.down * magnitudeDown);
- pressedS = true;
- }
- }
- else
- {
- if (data.inputA)
- {
- CmdAddForceToUTorsoRG(Vector3.right * -1 * magnitudeSide);
- walkA = true;
- }
- if (data.inputD)
- {
- CmdAddForceToUTorsoRG(Vector3.right * magnitudeSide);
- walkD = true;
- }
- }
- if (!isSliding && !isFlipping && !isSpeedDescending)
- {
- if (walkRaycast)
- {
- RaycastHit2D groundHit = RaycastDownReturnHit();
- if (groundHit.collider.transform.eulerAngles.z < maxAngleForWalk || groundHit.collider.transform.eulerAngles.z > 360 - maxAngleForWalk)
- {
- if (walkA) GetComponent<WalkAction>().CmdWalk(-1, groundRot);
- else if (walkD) GetComponent<WalkAction>().CmdWalk(1, groundRot);
- }
- }
- else
- {
- RaycastHit2D veloRaycast = VeloRaycast();
- if (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude > maxTimeTORemoveResistance) CmdSetMusclesToResist(1);
- else
- {
- float percentage = (veloRaycast.distance / playerVarsScript.uTorso.GetComponent<Rigidbody2D>().velocity.magnitude) / maxTimeTORemoveResistance;
- CmdSetMusclesToResist(percentage);
- }
- }
- }
- if ((isWalking && !walkA && !walkD) || (isSliding && !calledSlide))
- {
- StartCoroutine(SlowDown());
- }
- isSliding = calledSlide;
- isFlipping = calledFlip;
- holdingAOrD = pressedAOrD;
- isWalking = walkA || walkD;
- slideFrames = isSliding || holdingAOrD ? slideFrames + 1 : 0;
- isUpFromSlide = holdingAOrD && isUpFromSlide;
- isSpeedDescending = pressedS;
- jumpTimeCounter++;
- beforeJumpTimeCounter--;
- afterJumpTimeCounter--;
- CmdClampVelocity();
- CmdActivateMuscles();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement