- Home /
Trying to script "Beyond Oasis"-style crouch and jump
Beyond Oasis is a genesis-era game with input features I'm trying to emulate.
The objective here is to make the player jump if the crouch button is tapped (the first few frames of the crouch animation would be played before transitioning into the jump). If the crouch button is held, the player stays in the crouch and goes straight back into idle when the button is released.
This is the (dysfunctional) code I have so far:
float timepass = 0.0f;
float timelimit = 0.25f;
if (Input.GetButtonDown ("Duck")) {
anim.SetBool ("Duck", true);
if (Input.GetButton ("Duck")){
timepass += Time.fixedDeltaTime;
}
}
if (Input.GetButtonUp ("Duck")) {
if(timepass < timelimit){
anim.SetTrigger ("Jump");
}
anim.SetBool ("Duck",false);
float timepass = 0.0f;
}
Answer by FortisVenaliter · May 14, 2015 at 04:06 PM
Your Input.GetButton call, which checks if a button is held down, is inside the check for if a button is pressed this frame. Which means that timepass will only be incremented the first frame of the button press.
This is the closest to success I've come so far. Lingering problems:
The time detection feature is totally unreliable. No matter how low I set timelimit, jump is never triggered until I hold down the input for at least a full second. Sometimes I can keep the input held for several seconds and the trigger registers upon release -or sometimes before. Basically, the jump seems to get triggered at random but just tapping never sets it off. Aside from the randomness, this is THE OPPOSITE of what I'm trying to do.
When the jump trigger DOES register, the jump animation often (but not always) plays twice. Guess that's an extension of the first problem.
float timepass = 0.0f; float timelimit = 0.1f;
if (Input.GetButton ("Duck")) {
anim.SetBool ("Duck", true);
timepass += Time.deltaTime;
}
if (Input.GetButtonUp ("Duck")) {
if (timepass < timelimit){
anim.SetTrigger ("Jump");
}
timepass = 0.0f;
anim.SetBool ("Duck", false);
}
Answer by AviKohl3D · May 15, 2015 at 05:26 AM
I just achieved the effect I wanted via simple input scripts and animation states. Just need to tweak the anim clips to make it seamless.
The danger of needlessly over-complicating things never goes away.