Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

OnCollisionEnter not working

Discussion in 'Scripting' started by Mike L, Aug 3, 2011.

  1. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    for some reason, this isn't working
    Code (csharp):
    1. void OnCollisionEnter (Collision hit) {
    2.     //if (hit.impactForceSum.magnitude > 10) {
    3.         Debug.Log("yay");
    4.     //}
    5. }
    its not registering the collision and saying yay in the console

    Edit: i forgot to tell you, its a capsule collider, and isTrigger is false
     
  2. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Is your other collider having rigidbody or any rigidbody attached to this collider. On colllision will only be called when one of the colliders have a rigidbody. Take a look at this. OnCollisionEnter.
     
    Last edited: Aug 3, 2011
    MilosPolo and StinkyDubeau like this.
  3. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    ah, thats what is missing, thanks man
     
  4. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    new problem, now its colliding with something i really dont want it to, ill try something and see if it works in the future...
     
  5. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  6. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    Yeah, i know about that, but if i try that, that takes more time to set up, i just decided to do it a bit differently
     
  7. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    If you set the other collider to be a trigger only, it should work, if I understand your issue correctly. That is what the isTrigger is for.
    You may also need to set the new collider to isKinematic, though I don't see that changing the way the collider works, just to stop it from being processed by PhysX.
     
  8. msue2

    msue2

    Joined:
    Jun 2, 2017
    Posts:
    1
    Another possible issue: The order of Rigidbody and Collider components on the game object. This requirement is not documented on the OnTriggerEnter page. Tested on 2017.4.

    The Rigidbody component must be added first, followed by the Collider component. The order of already added components can be changed in the inspector cogwheel dropdown with "Move Up"/"Move down".
     
    megabrobro likes this.
  9. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    100
    You are a hero today sir
     
    GhostSlayer44 likes this.
  10. rodrigoschmidtgodinho

    rodrigoschmidtgodinho

    Joined:
    Apr 9, 2020
    Posts:
    1
    your collider is too small. too small.Increase your size.
     
  11. bionicartsmobile

    bionicartsmobile

    Joined:
    Apr 21, 2019
    Posts:
    1
    Might be a silly answer, but sometimes the little things are missed.

    I ended up on this post and couldn't figure it out. Come to find out, I forgot to attach the script to my projectile gameObject.

    Make sure your script is attached! =D
     
  12. dimitriskalogeropoulos3

    dimitriskalogeropoulos3

    Joined:
    Jul 7, 2019
    Posts:
    1
    also make sure the rigidbody is not kinematic
     
unityunity