Advertisement
Guest User

Untitled

a guest
Apr 29th, 2021
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Hey I would try to access the horizontal movement only when the player is doing a jump. Something like
  2.  
  3. if (CrossPlatformInputManager.GetButtonDown("Jump") && hasJumps > 0)
  4. {
  5. double jumpHorizontalVelocity;
  6. if (CrossPlatformInputManager.GetButtonDown("MoveRight")) {
  7. jumpHorizontalVelocity = jumpHorizontalSpeed;
  8. } else if (CrossPlatformInputManager.GetButtonDown("MoveLeft")) {
  9. jumpHorizontalVelocity = -jumpHorizontalSpeed;
  10. }
  11.  
  12. Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
  13. myRigidBody.velocity += jumpVelocityToAdd;
  14. myRigidBody.velocity.x = jumpHorizontalVelocity;
  15. isJumping = true;
  16. --hasJumps;
  17. }
  18.  
  19. if (!myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }
  20. {
  21. hasJumps = 1;
  22. isJumping = false;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement