Search Unity

Using Rigidbody2D to move and jump

Discussion in 'Physics' started by Givago, Apr 25, 2017.

  1. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    Good Night,
    I was using addforce and transform.Translate to jump and walk, but to leave everything the same I changed to
    Rigidbody2D velocity;

    Code:

    However when walking in the air the gravity changes and jumping does not work walking and is weak even with very high var.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Not sure what you mean about gravity changing.

    If you want to set the walking speed, you can simply set the velocity and not incorporate time.delta time.
    Think of it.. You say, I want it to go: new Vector2(10,0,0);
    It's velocity is now 10 (and i guess there might be drag there, too..), but basically the thing is moving how you want.

    As for jumping , it's almost the same thing. Using the velocity for a jump is possible, and you could try the same thing (not using deltaTime, I mean, and probably need a lower value then). However, you could also try 'AddForce' which may be a bit nicer for a jump.