Problem detecting two objects with OnTriggerEnter2D

Hello!
Here’s my problem! I have a ground that I tagged as “Ground”, so if you are not on the ground, player could not jump.

Now … I wanted to make my enemy jump so I thought i could use some “jump points” and so I did!

Created empty objects, tagged as “JumpPoint” and inserted this on my enemy script:

public void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("Collision with: " + collision.tag);
        if (collision.tag == "JumpPoint")
        {
            enemyRb.AddForce(new Vector2(enemyRb.velocity.x, enemyJumpForce));
        }
    }

That “Debug” says: groundgroundgroundgroundgroud… and never “JumpPoint”. So my enemy never jumps!

Where’s my mistake this time? :smile::smile:

As usual, thanks for your precious help!

P.s.
Yes! I am sure I tagged jumpPoints! :stuck_out_tongue:

Hi @Feretro ,

You said “I am sure I tagged jumpPoints” but in your code you write “JumpPoint” so are you 100% sure you’re written those names exactly correct.

Also, when you say “empty objects”, did you add triggers to them?

1 Like

Hi Olmi! :smile:
Yes, yes, names are correct but … ehm … :sweat_smile: no, I have no trigger on those “empty object” … don’t tell me …

Oh … yes, you told me! Now It works … It jumps!!! … In a really strange way but it works!

Thanks for your help!!!

1 Like