Search Unity

Jumping

Discussion in 'Physics' started by StamiDeveloper, May 18, 2020.

  1. StamiDeveloper

    StamiDeveloper

    Joined:
    Oct 8, 2017
    Posts:
    5
    Hi!
    I wrote script on jumping using AddForce:

    GetComponent<Rigidbody>().AddForce(0, jumpForce, 0, ForceMode.Impulse);

    My object is jumping, but sometimes higher, sometimes lower - like in the movie:


    How to make jump always at the same height?

    Thank you in advance for help.
     
  2. samdaman93

    samdaman93

    Joined:
    Oct 3, 2015
    Posts:
    37
    I would set velocity in the vertical direction to 0 before the next jump. I'm assuming the jump force is being applied when the object is still travelling down, or the object might be bouncing when the force is added.

    Also you don't need to get component every time you want to jump. Just get component in the start function and add force when you want to jump
     
    StamiDeveloper likes this.