- Home /
Question by
gedadh · Jun 06, 2019 at 08:06 PM ·
2d gamecollider2dtag
Tag and Collider problem
This is my player's jump code:
if (isJumping == false && moveVertical >= .7f)
{
moveVertical = Speed * 70;
isJumping = true;
}
ball_move = new Vector2(moveHorizontal, moveVertical);
ball_rigid.AddForce(ball_move);
------------------
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Ground")
{
isJumping = false;
}
}
When ball touches under of the collider it can jump again. How can i block this situation ?
sorun.png
(224.1 kB)
Comment
Answer by MacDx · Jun 06, 2019 at 08:13 PM
The Collision2D parameter contains information about the collision. It has a contacts array that describes the collision points, each of these collision points contain a normal which is the outwards direction of the face/edge you collided with. You can use that to determine what side of the block you collided with (i.e. if the normal is pointing downwards (x 0, y -1f)) and then make it so you can't jump if you touched it from below.
Your answer
![](https://koobas.hobune.stream/wayback/20220612202744im_/https://answers.unity.com/themes/thub/images/avi.jpg)