- Home /
Delay jump to confirm player really wants to jump
so that after the player has held space for 0.25 seconds, jumping = true :)
can you define it a little more , is the space means a keyboard key or just a platform space . Then what you actually want is the player doesn't react until 0.25 sec after when space pressed and then jump or jump = true . If yes then you will find my answer helpful .
space key. i want the player to have to hold space for 1/4 of a second before it jumps. but i want the player to not just be able to hit jump, then hit it 1/4 second after, thats why a coroutine doesn't work.
Now i got it looks invoke also not works for this . I have to find out other solution for this .
Answer by JeevanjotSingh · Jan 04, 2015 at 07:20 PM
just use update() function .
and in update use something like
public bool jumping = false;
void update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Invoke("TheFunction",0.25f);
}
}
void TheFunction()
{
jumping = true;
}
Not tested but , looks like it works
let me know if it works or not .
doesn't this cause the player to jump after 0.25 seconds, even if the player didn't want to? you might want to add a cancel invoke function during Get$$anonymous$$eyUp to cancel the jump if they player only tapped the space key.
No problem and let me know if the first code works , if not i will insert this code with one more condition to identify invoke .
if(Input.Get$$anonymous$$eyUp(keycode.space))
{ CancelInvoke("TheFunction") }
I also got another solution with time delay .
use Input.Get$$anonymous$$ey($$anonymous$$eyCode.Space) ins$$anonymous$$d Get$$anonymous$$eyDown() and on each frame add time.delta time to float and if it will == or >= 0.25 then player can jump or jump == true , if not them just continue the game .
"No, it never jumps because it invokes jump while space is held"
That's why now i am not preferring the invoke or cancel invoke (because it didn't make any sense to hold the button) but as i explained other way you can try that and tell if you have any problem with the new code about use Input.Get$$anonymous$$ey($$anonymous$$eyCode.Space) etc.....