Search Unity

Collision with empty game object edge collider 2d stops player

Discussion in 'Scripting' started by johnc81, Jun 20, 2019.

  1. johnc81

    johnc81

    Joined:
    Apr 24, 2019
    Posts:
    142
    Hello,

    I am struggling with something that I thought would be easy...until I tried :)

    I am making a 2D game and have a spaceship that I want to land on platform. My spaceship has a Polygon Collider 2D (Is Trigger = true) and a RigidBody 2D component. I have created an empty Game Object with an Edge Collider 2D (Is Trigger = true) and a RigidBody 2D component. I am using an Edge Collider due to the shape of the platform.

    What I want to do is that when the Spaceship lands on the platform, it stops. Right now, it just goes right through. I have tried a few different things including scripts, tried using a Box Collider 2D, OnTriggerEnter2D etc. but cannot get this to work.

    Please can someone point me in the right direction because I really don't know what I am missing :(

    Many Thanks,

    John
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Triggers won't stop anything. They only send enter, stay, exit events and that's it. Triggers are used to trigger logic events in game, like if you ship enters bonus trigger, the bonus is taken and activated. But this will not affet rigidbody in any way. Turn off trigger mode if you want colliders to actually collide with rigidbodies.
     
  3. johnc81

    johnc81

    Joined:
    Apr 24, 2019
    Posts:
    142
    Hi,

    Thank you for your reply. I have turned off the trigger on the Player and Platform PolygonCollider2D and now it doesn't go through. I am doing that on the Player with OnTriggerEnter2D and have permanently set the Is Trigger = false on the platform.

    How do I get the trigger to be marked as active again once the player moves away from the platform because this is not working with OnTriggerExit2D.

    Thanks,

    John
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    OnCollisionExit2D should work when collider is not trigger.
     
    johnc81 likes this.
  5. johnc81

    johnc81

    Joined:
    Apr 24, 2019
    Posts:
    142
    Hi,

    Forget that last post, I misread your comment. I read it as OnTriggerExit2D, not OnCollisionExit2D. Now it is working perfectly, thank you very much :)

    Many Thanks,

    John