Search Unity

Collision issues unity 2017.1.3.1f

Discussion in 'Physics' started by voymasa, Mar 20, 2018.

  1. voymasa

    voymasa

    Joined:
    Aug 23, 2017
    Posts:
    3
    I am setting up a collision I. The editor where a 20s sprite character with a box collider and rigidbody (both 2d) can collide with a 2d box trigger collider. The unity collision matrix shows that it should register a collision, but my console message doesnt fire off when I enter or exit the collider (I have tried both the oncollisioneneter2d, and exit methods).
    The physics system doesn t seem to register the collision.

    In not at my computer at the moment but my code is basically
    OnCollisionEnter2D(Collider2D coll)
    {
    if(coll.gameObject.tag == "Player")
    {
    print("you have entered.")
    }
    }

    Print is another way of console.debug. the message isn't displaying to the console
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Are you sure its the OnCollisionEnter2D failing and not the if(coll.gameObject.tag == "Player") comparison? Just do a print statement without the tag check and see if that works first.
     
  3. voymasa

    voymasa

    Joined:
    Aug 23, 2017
    Posts:
    3
  4. voymasa

    voymasa

    Joined:
    Aug 23, 2017
    Posts:
    3
    @karl_jones
    That I'm using a trigger collider for the stationary collider, should I be using OnTriggerEnter2D instead?
    https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281