Search Unity

Sphere refusing to enter trigger area

Discussion in 'Physics' started by Chiligoat, Jun 25, 2019.

  1. Chiligoat

    Chiligoat

    Joined:
    Jun 12, 2019
    Posts:
    3
    [SOLVED]
    Hi all! This is my very first foray into 3D and Unity, so my question is very basic.
    I have my player object pushing a sphere (from now on referred to as a ball) around. Both of these objects have rigidbodies so that they can collide with things, though for now, the player char is kinematic to avoid messing up facing direction/key-press. I've also set up a simple box collider that, when the ball enters it, pops text up on the UI layer for a little while. So far so good.

    However, the ball refuses to enter the trigger area. It brushes up against the collider area and triggers, sure, but it doesn't move through it but acts like it's hit a wall. I figure it's because the box collider's "is trigger" isn't ticked, but here's the thing: if I do tick "is trigger".. nothing happens. The ball goes straight through it and doesn't trigger the script.

    I've tried giving the box collider/trigger area a rigidbody, I've turned gravity on/off, I fiddled around with meshes. I moved the script around so that it'd destroy the object in collision just to double check that it's not a badly written script, but that also only works when the trigger area doesn't have "is trigger" ticked and functions like a hard wall... What am I doing wrong? Thanks so much in advance!
     
    Last edited: Jun 30, 2019
  2. arahmitz

    arahmitz

    Joined:
    Jun 25, 2019
    Posts:
    25
    Do you use OnTriggerEnter2D instead of OnCollisionEnter2D?
     
  3. Chiligoat

    Chiligoat

    Joined:
    Jun 12, 2019
    Posts:
    3
    Nope: it's a 3D scene with 3D objects and I'm using OnCollisionEnter.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    You're using OnCollisionEnter on your trigger, not OnTriggerEnter? Sounds like you're just not using OnTriggerEnter, which is what you need for triggers.
     
    Chiligoat and arahmitz like this.
  5. arahmitz

    arahmitz

    Joined:
    Jun 25, 2019
    Posts:
    25
    Do not ask why I though you were working with 2d. Still dgoyette is right - you should use OnTriggerEnter/OnTriggerStay/OnTriggerExit when you're working with isTrigger clicked.
     
  6. Chiligoat

    Chiligoat

    Joined:
    Jun 12, 2019
    Posts:
    3
    cc: @arahmitz

    I-- Yeah, that's exactly what the problem was. I'd been watching a bunch of vids about collisions and the importance of using oncollision instead of ontrigger and that late at night, brain just fried. Thanks a bunch!