0
\$\begingroup\$

I'm trying to make Flappy Bird, but when I put an EdgeCollider2Don the Pipe, the bird can't pass through the collider and gets stuck.

Bird code:

{
    Rigidbody2D Rb;
    public float jumpForce;
    
    float score; 
    
    void Start()
    {
        Rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            Rb.velocity = Vector2.up * jumpForce;
        }
    }
    
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.gameObject.tag=="Point")
        {
            score++;
        }
    }
}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Did you mean to set one of the colliders as a trigger, if you want the other one to pass through it without being blocked? \$\endgroup\$
    – DMGregory
    Feb 17, 2021 at 5:01
  • 1
    \$\begingroup\$ You want to go through the pipe? Isn't the goal of the game to not hit them? \$\endgroup\$
    – Zibelas
    Feb 17, 2021 at 7:34
  • \$\begingroup\$ @Zibelas I believe he means a collider in between the pipes, which gives points when collided with. \$\endgroup\$ Feb 17, 2021 at 16:37

1 Answer 1

0
\$\begingroup\$

As far as I am understanding your question, you are trying to give the player a point when he collides with the collider in between the pipes. Just simply add the “Point” tag to your GameObject with the EdgeCollider2D attribute. Then, set the IsTrigger box to checked. This makes it trigger the OnTriggerEnter2D(Collider2D other) method on collision instead of colliding with the player.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .