Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

DontGoThroughThings still goes through things

Discussion in 'Scripting' started by sbuchbinder, Jun 13, 2008.

  1. sbuchbinder

    sbuchbinder

    Joined:
    Apr 4, 2008
    Posts:
    53
    I've added the DontGoThroughThings script to my hockey puck...but it keeps going through the table mesh.

    http://www.ksbdigitalstudios.com/dev/unity/airhockey/


    I'd also like to know why I can't do an OnCollisionEnter if the gameObject just has a MeshCollider....

    any help would be appreciated.
     
  2. kattkieru

    kattkieru

    Joined:
    Jan 2, 2006
    Posts:
    130
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I've run into a similar issue. I have a very large terrain mesh (not a Unity terrain) with a mesh collider and a large number of rigid bodies with box colliders. I've tried the "do not go through things" script as well as the "convex" toggle on the mesh collider, but still a percentage of my objects still fall through. I tried increasing the density of the terrain mesh, but my terrain grew to a poly count before I noticed any change. After hours of experimenting with this I found that whether the small objects fell through the large mesh was effected by a) the overall physics load in my game and b) whether my objects colliders were much smaller than the terrain mesh collider. Since my terrain mesh is relatively large (a couple hundred meters across) and my objects are relatively small (several centimeters across) I haven't really found any good solutions to this issue.

    The reason I'm adding this is because if the above advice doesn't work you may be running into the same situation I am. I think the only way to fix my situation will be to lessen the overall physics load, but I haven't figured out a way to do that yet (my game is very physics intensive).
     
  4. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    566
    I've been working on a hockey game as well and have seemed to get the DontGoThroughThings script to work well on my puck.

    Here's what I have done:

    1] I made project settings -> physics -> min penetration for penalty insanely small - mine is set for 1e-20! Makes sense since the puck is rather small.

    2] Take a look at the line of code:
    Code (csharp):
    1. skinWidth : float = 0.1; //probably doesn't need to be changed
    Well, I did change it to 1.0.

    3] Take a look at this line of code:

    Code (csharp):
    1.  if (Physics.Raycast(previousPosition, movementThisStep, hitInfo, movementMagnitude, layerMask.value))
    2.          myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent;
    3.  
    I changed movementThisStep/movementMagnitude to movementThisStep*movementMagnitude.

    I can't remember why, it doesn't make sense to me now, but it's all working.

    Also, make sure your puck is not in your raycasting layer.

    Mitch
     
  5. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    In my tests, I found no significant difference between setting this to 0.001 or 1e-20 (or anything in between). I only tested this in the editor not a standalone, and my application is a bit different than yours.
     
  6. dayglo

    dayglo

    Joined:
    Apr 28, 2010
    Posts:
    24
    Thank you Thank you Thank you! Been working on this for hours and this fixed it for me.
     
  7. pn99

    pn99

    Joined:
    Feb 9, 2012
    Posts:
    20
    ... for me reducing the value even lower caused jitters.