Search Unity

Convex Colliders won't collide

Discussion in 'Scripting' started by Recluse, Feb 23, 2011.

  1. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I've been using Unity for over a year and a half and suddenly I'm having a really basic problem!

    I've got two different objects, both with convex mesh colliders. Neither will collide.

    I've checked the collision Matrix in the physics settings. I've tried adding a rigidbody to both of them, marked it as Kinematic, but this doesn't work.

    The only way I can get the objects to collide is to add a non-kinematic rigidbody to one. But this is then affected by Physics, which I don't want.

    Is there no way to get two convex mesh colliders to register contact?
     
  2. lasco

    lasco

    Joined:
    Nov 12, 2009
    Posts:
    101
    Did you check your collider meshes don't have more than 255 triangles ?
    It they do then no convex collision…
     
  3. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Both the collider meshes are under 65 triangles - originally I was using primitives, but replaced them with simple meshes built in Blender so I could try convex collision. Now I know Unity can handle collisions between meshes that don't have rigidbodies but I'm damned if I can get it to work in this case. Only works if I attach a non-kinematic rigidbody....
     
  4. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    What happens if you attach a kinematic rigid body to one?
     
  5. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Doesn't work with a kinematic rigidbody. If I change the value in the inspector while running to make the rigidbody non-kinematic it works instantly. Why not with kinematic? I thought that would register a collision with convex mesh collider.... I am stumped...
     
  6. lasco

    lasco

    Joined:
    Nov 12, 2009
    Posts:
    101
    Ah ok I had missed that one.

    Your issue is not "convex or not convex."
    It's kinematic which disables physics.

    Read the doc :

    Guess you must look for another way to do what you want…

    maybe some script that enables / disables iskinematic when needed / not needed ?
     
    Last edited: Feb 24, 2011
  7. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I read the doc many times. I don't want physics - at all.

    I simply want two colliders to detect when they touch.

    But I can't get this to happen unless I add a non-kinematic rigidbody.

    So my question is: How do I get two mesh colliders / primitive colliders to register collision, without physics?
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    then you want physics.
    without physics colliders never move and thus also will never detect a new collision (something that can not move can logically not start touching something either, either it always did or it never does)

    you would then not use colliders at all anymore, but raycast and alike
     
  9. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Where the doc says "kinematic rigidbodies are not affected by collisions" I am assuming they still register contact - only that they are not affected by any forces, due to physics. Anyone at Unity confirm this?
     
  10. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I'm moving the colliders via their transform in script.

    I have two boxes - one static, one controlled by the player via transform in script.

    I simply want the boxes to register if they touch. Why introduce physics? Aren't convex colliders and non-kinematic rigidbodies for this very purpose?
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    skip this
     
    Last edited: Feb 24, 2011
  12. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    There must be hundreds of situations where you don't want the overheads of physics calculations, especially if you are moving things that have no force of inertia etc. (i.e something that moves instantly to the mouse position on screen).

    How do you detect a collision between two meshes, without physics? As mentioned, non-kinematic and convex don't appear to do it.

    If I make the colliders triggers, then other objects in the game which are physical won't bounce off them.
     
  13. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I don't know if I made myself clear Dreamora, I just want a result from OnCollisionEnter. No Physics, no forces, just confirmation if the objects touched.
     
  14. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    I mean the doc clearly states Convex colliders can collide with other convex colliders. Except mine won't register the contact. And I've checked everything - collision matrix etc...
     
  15. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Here's a quick example project, with two convex mesh colliders. They don't register collisions. Why not?

    http://www.iwari.com/unity/
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    They won't; see the collision matrix at the bottom of this page in the docs. As you can see from that chart, though, two kinematic triggers will register OnTriggerEnter, so you might be able to use triggers. This is reasonable because programmatically moving an object inside another object should not happen as far as physics is concerned; in order to get any kind of collision info that makes sense, it has to come from the physics engine. This is why OnCollisionEnter has Collision info passed in, whereas OnTriggerEnter only has Collider info. If you can't use triggers and need colliders, then one of the objects must be non-kinematic, and in order to move it completely deterministically instead of with forces, you can use Rigidbody.MovePosition instead of Transform.Translate.

    --Eric
     
  17. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    Thanks Eric, you're right - the info is there (though the collision matrix in the user manual isn't clearly presented (could do with being in a marked grid with a bit more spacing around the entries as it's hard to scan).

    I went astray where the docs state 'convex colliders can collide with other convex colliders'. That statement in isolation is a bit misleading.
     
  18. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Hey, I know this thread is really old, but I'm running into your same problem. I don't have a a solution though. Very simple setup. I have asteroids with rigidbodies and I have asteroids without. They both have mesh colliders, neither is a Trigger. When I press play and fly around, I watch the smaller asteroids float around AND through each other. I have scripts on the static asteroids that should blow up the smaller asteroids OnCollisionEnter. Unfortunately, the static asteroids aren't reading collisions either! All the asteroids have no collision detection. However, when I shoot them with lasers, the lasers read the collision and apply damage, then blow up. Also, enemy spaceships (that also have rigidbodies and move by applying force) will register collisions with asteroids and knock the dynamic ones around! I have been using Unity for over a year as well and I have no idea why this is happening. Am I just being retarded and forgetting something obvious? Either way, I have a deadline and I can't figure this out. Help would be greatly appreciated from someone (especially from Unity). I've exchanged the mesh colliders for sphere colliders, when I do that the collisions work perfectly (besides the fact that lasers wont hit perfectly on the asteriods). I would really like to be able to get collisions from a non convex, normal mesh collider.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can't use non-convex mesh colliders for this.

    --Eric
     
  20. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    for collisions?
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Correct. Also it's bad for performance to have moving mesh colliders.

    --Eric
     
  22. subjectZero

    subjectZero

    Joined:
    Oct 19, 2014
    Posts:
    37
    Then how do you have physics on a car (player) crashing into another car?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use primitive colliders.

    --Eric
     
  24. subjectZero

    subjectZero

    Joined:
    Oct 19, 2014
    Posts:
    37
    Last edited: Mar 8, 2015