Spam jumping issue.

Hi There!

So I’m a beginner at coding but watching several videos I have figured out a First Person controller code.
I can show the code if someone wants to see it and figure out my problem. The code as first when O rewrote it from the video was only for moving the character horizontally and vertically. I then added a jumping feature that is working. But if you spam the space button you keep getting upwards. Does anyone know what type of function to add so you only can jump up once until you land? Or hint me how you make a time limit sort of thing. I don’t want a code.

//Victor

Use this method:

public Transform groundCheck;
public LayerMask groundMask;
public float groundDistance;

public void IsGrounded()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
}

Put an empty object at the bottom of your character, and also make sure to create a tag for your ground.

This method creates an invisible sphere, taking the empty object as the center, and the groundDistance as the radius, and when it collides with the object with the ground tag, it returns true

So before you enter your jump state, you check if the character is grounded

Add a counter that will count the jump button presses while in air (managed via a boolean that is true when the first jump is issued and false once the character collides with the ground collider) and trigger the jump function only when the counter is at a value low enough, incrementing the value after running the jump function.