Search Unity

Infinit jumping through platforms in 2D

Discussion in '2D' started by bogdan241199, Oct 28, 2020.

  1. bogdan241199

    bogdan241199

    Joined:
    Feb 26, 2020
    Posts:
    3
    So I have my player that can do a single/double jump and can jump again after touching the "ground" and I consider "ground" anything on the ground layer. In my game I olso have platforms with one way collider (so i can jump from under the platform on top) and the platforms are olso ground so I can land/jump from them. To check if I touch the ground I use a raycast2D

    Code (CSharp):
    1. Physics2D.Raycast(groundCheck.position, Vector2.down, groundCheckDist, whatIsGround);
    2.  
    where groundCheck is a GO that I set in inspector

    upload_2020-10-28_13-34-51.png

    As you can see the raycast is very small but it still collids with the platform when jump on it so the player is cosiderd to be grounded so I can jump again. And if I have multiple platforms I can basiclly fly through all of them and I don't want that
     
  2. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    Can check for amount of time passing before allowing another jump after being grounded; reset whenever not grounded.
     
  3. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    make a new groundedvarForDoubleJump that checks for grounded only if your character is falling. ( velocity,y < 0 )