Search Unity

Floats after jump

Discussion in 'Getting Started' started by hrohibil, Jun 21, 2021.

  1. hrohibil

    hrohibil

    Joined:
    Apr 17, 2021
    Posts:
    280
    Hello

    Please see my code.

    When i jump diagnollay it looks sort of ok, but if i just press the jump so the player makes a straight vertically jump, then when he falls down he just floats slowly towards the ground..

    I can move the right and left keys to make the fall faster for some reason.

    Please advice..



    Code (CSharp):
    1.  if(Input.GetKey("space") && IsGrounded == true || Input.GetKey("up") && IsGrounded == true)
    2.         {
    3.             Debug.Log("JUMP PRESSED");
    4.             //jump
    5.             //gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 1000f), ForceMode2D.Impulse);
    6.             // Vector2 movement = new Vector2(myRB.velocity.x, jumpPower);
    7.             //myRB.velocity = movement;
    8.             myRB.velocity = Vector2.up * (jumpPower) * Time.fixedDeltaTime;
    9.              //myRB.velocity = new Vector2(myRB.velocity.x,  jumpPower * Time.fixedDeltaTime);
    10.              animator.Play("Player_Jump");
    11.         }