Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Collision problem ... now in Unity5

Discussion in 'Unity 5 Pre-order Beta' started by cedhikari7, Apr 18, 2014.

  1. cedhikari7

    cedhikari7

    Joined:
    Feb 6, 2014
    Posts:
    15
    Hello guys !

    I have been around for some time but now I have a chance to begin working with unity.
    And now things are beginning harder than in tutorials :D

    I am trying to solve a collision problem which is probably a classic one, trying to do the minimum of work 8) (I chose unity for that :p).
    I have balls in an empty cube rotating and the problem is that balls are passing through the cube after a while.

    I have read some infos on this problem, and it seems it is because the ball collider is passing through my cube face collider before physics is able to see it. The problem is probably occuring when a ball is near a wall and has time to pass the collider before next physic iteration.

    How will you address this problem ?

    $Capture.PNG

    I have attach a sample project.

    Cheers,
    Cedric
     

    Attached Files:

  2. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    Try to up the solver iterations count in your project's physics settings and see if that helps. Here are the docs.
     
  3. cedhikari7

    cedhikari7

    Joined:
    Feb 6, 2014
    Posts:
    15
    So I just tested out this old sample to check how things where doing in Unity5 ... on Unity blog, they say that PhysX 3.3 is so awesome that you just activate CCD and it works ... not after upgrading the project here ... or is there something more to do to upgrade my old project and have collision working without adding tricks ?!
     
  4. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    You explained it yourself:
    "The problem is probably occuring when a ball is near a wall and has time to pass the collider before next physic iteration"

    I'm guessing that "solver iterations" is the ticks of the physics engine and then it isn't a trick. You are simply increasing the update rate, meaning that collision checks is happening more often, the balls do get the time to travel so far before next the next collision check is done.

    Other ways to solve this includes but isn't limited to clamping the balls speed so that they can never travel at a speed that out-pace the physics engine or write your own collision system that predicts, ahead of time when the next collision will happen for each object.

    Your specific problem happens all the time in AAA games as well, often when players do something that give them a speed that they were never meant to have within the game and BAAAM! You got caught inside a building, collision volume, fell through the world or got stuck half-way through a monster... insert funny graphics when the game is trying to resolve some of the situations ;)
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    How do you rotate your cube? I could imagine that it makes a difference if you change transform.rotation or if you use forces.
     
  6. Aurore

    Aurore

    Director of Real-Time Learning

    Joined:
    Aug 1, 2012
    Posts:
    3,106
    This isn't gossip, moving to support.
     
  7. cedhikari7

    cedhikari7

    Joined:
    Feb 6, 2014
    Posts:
    15
    oups :( ... sorry for posting in the wrong section.

    @Carpe Denius ... I am moving it using trnasform.rotation. I see what you are suggesting, I will try with force to check

    EDIT : just tried setting angularVelocity instead of rotating transform but balls are passing through walls ...
     
    Last edited: Nov 6, 2014
  8. cedhikari7

    cedhikari7

    Joined:
    Feb 6, 2014
    Posts:
    15
    @Deon Cadme ... I naively understood PhysX 3.3 will solve my problems since Unity is stated "just check continuous detection and it works ..." on their blogs. I will try to check and clamp balls velocity but my sample is not a bullet shot, balls and walls are not moving that fast
     
  9. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    If you translate it by yourself and rotate the ball through your cube, physx doesn't even have to check for collisions because you are "beaming" it to a new position. Try and rotate it with forces
     
  10. cedhikari7

    cedhikari7

    Joined:
    Feb 6, 2014
    Posts:
    15
    I tried by setting angularVelocity to the rigidbody in Start but balls are always passing through
     
  11. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Maybe you are still bypassing the force calculations with that.
    http://docs.unity3d.com/ScriptReference/Rigidbody.html
    The methods you are looking for are AddTorque and/or AddRelativeTorque

    You don't have to use a script for testing, use the component "ConstantForce".
     
  12. cedhikari7

    cedhikari7

    Joined:
    Feb 6, 2014
    Posts:
    15
    Thank you for pointing out "ConstantForce" script and your help.
    But unfortunately, same result with it.
     
  13. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Can you export your scene? I'll test it
     
  14. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    You should be changing the rigidbody's rotation not the transform's rotation. Changing the rigidbody's position/rotation tells the physics engine that you are wanting to move through the physical world. If you change the transform's position/rotation you "teleport" without any regard to physics.
     
    Last edited: Nov 7, 2014
  15. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    It's common and known problem with physx. Problem is that theres no easy way of fixing this. CCD is a must as you already know, next thing you should do is lower fixed timestep in Project Settings > Time. But be aware that it WILL lower performance, lower fixed timestep means that physx calculations are done more frequently and this of course means that it will need more cpu power. But its the only way to make physx more "precise", and precision is what you need here, another thing you can try playing with is min penetration for penalty in Project Settings > Physics, but it's last thing you should try, hope this helps ;)