V
V
Vqrlamov2021-07-23 17:12:13
Unity
Vqrlamov, 2021-07-23 17:12:13

How to make a 2D jump from the ground when you click on it in the air?

How to make it so that when you click on the jump zone in the air, while the character himself is in the air, the system seems to remember this action and when the character touches the ground, the jump will work?

code:

void Update()
{
if (!coll.IsTouchingLayers(Ground))
{
onGround = false;
}
else
{
onGround = true;
}
}

public void OnJumpZoneClick(int Jump)
{
if (onGround == true && Jump == 1)
{
rb.velocity = new Vector2(rb.velocity.x, JumpForce);
}

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ReyGrau, 2021-07-27
@ReyGrau

You create a boolean field, then check if the "jump zone" is pressed and the character is in the air, then you assign true to the field, then check (is your field equal to true and the character is on the ground?), then you make a jump and assign the field false.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question