c# - Short jump and large jump with Strength of Keyboard input -


i met problem when jumped gameobject. make action largjump , shortjump. problem how can make conditional statement. want distinguish weak keyboard input, , strong keyboard input.

here code.

if (input.getbuttondown("jump")) {     float jumptime = 0;     jumptime = jumptime + time.deltatime;     if (input.getbuttonup("jump") && jumptime < 0.3f)     {         playerctrl.actionshortjump();     }     else if (input.getbuttonup("jump") && jumptime > 0.3f)     {         playerctrl.actionjump();     } } 

getbuttondown returns true first frame button pressed, never jump since button cannot down , on same frame. need use getbutton increase jump time while button held down, , getbuttondown reset timer when button first pressed, while declaring jumptime outside of overall method.

float jumptime;  void update() {     if (input.getbuttondown("jump"))     {        jumptime = 0;     }     if (input.getbutton("jump"))     {         jumptime = jumptime + time.deltatime;      }     else if (input.getbuttonup("jump") && jumptime < 0.3f)     {         playerctrl.actionshortjump();     }     else if (input.getbuttonup("jump") && jumptime > 0.3f)     {         playerctrl.actionjump();     } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -