Ok, so I know that the FPS microgame is supposed to be beginner friendly, and I am a beginner. But how exactly would I go to add a double jump in it?
Its actually pretty simple if you already have a way to jump. What you can to is create a boolean called something like canDoubleJump. Just set this value to true anytime you touch the ground:
bool canDoubleJump;
private void OnCollisionEnter (Collision col)
{
if (col.gameObject.layer == "Ground")
{
canDoubleJump = true;
}
}
This just sets the bool, so that you can can double jump after you have touched the ground.
Now whenever you hit the spacebar, and are not touching the ground, check if the bool is active, and if it is call your jump function:
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (!isGrounded && canDoubleJump)
{
Jump(); //call your jump function here
canDoubleJump = false; //so you cant jump forever in the air
}
If you dont have a groundCheck object you will need to make one, but if you can already jump normally, i assume you already have a groundCheck.
I would somehow make it to where once you jump (or if double jump is enabled) it sets another ground object that is above the ground (and transparent) active that automatically bounces the player again to make it look like a double jump.
Ex: `if(doubleJump){
secondGround.SetActive(true);
}
private void OnTriggerEnter(Collider other){
if(other.CompareTag(“DoubleJumpPlatform”){
Jump();
}
}
`