Search Unity

Code for Jump Height?

Discussion in 'Scripting' started by Draxonis-N, Aug 30, 2015.

  1. Draxonis-N

    Draxonis-N

    Joined:
    Aug 25, 2015
    Posts:
    7
    anyone know the Code for controlling jump height? It's something I'll need for the player controller.

    jump height as in the player can just hop if they press the jump button quickly or jump full height if they hold it down.
     
  2. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    If your developing your own controller just make a variable that has a float value. If the person presses spacebar, increase the rigid body's velocity in the upward direction by your float value.
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Or addforce.force I think adds more force the longer you hold the button down but that gets tricky to balance between a small hop on first press or flying off the screen if you hold it down to long
     
  4. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    AddForce is much better for the addition of force constantly. In this case we can guess that the force wont be constant therefore it is better for rigidbody.velocity to be used!
     
  5. Draxonis-N

    Draxonis-N

    Joined:
    Aug 25, 2015
    Posts:
    7
    I guess I should head over to some unity scripting tutorials because I don't know what I would write after
    "Public Float jumpHeight" to put it into effect.
     
  6. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    @Draxonis-N That would probably be best. If you still need some more help just come and ask :)
     
  7. Draxonis-N

    Draxonis-N

    Joined:
    Aug 25, 2015
    Posts:
    7
    going through the beginner scripting, still 0 idea what I need to type in the update to give the player control of how high they jump :/