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
Post a Comment