Search Unity

What are the necessary settings to prevent objects passing through each other at high speeds?

Discussion in 'Physics' started by Nanako, Feb 7, 2016.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    I looked into this problem about a year ago, didn't find an ideal solution then, i did find a sort of hack involving raycasting and prediction that filled the gap for now, but it's hardly optimal.

    I'm sure unity has had some updates, i think it's worth another try;

    Assuming i have a wall, made of non-kinematic physical objects with rigidbodies (Or possibly it is a static wall without a rigidbody, different use cases) and that the other object is a flying physical projectile with a non-kinematic rigidbody;

    What settings can i use to ensure that these objects always collide, and thatno matter how thin the wall is, or how fast the projectile is moving, one never goes through the other without registering a collision?

    This seems like a feature any good physics engine should have, i'm saure PhysX must have support for it.
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    723
    Change collision detection mode on the Rigidbody(s) from discrete to continuous. More overhead, but better collision detection.

    rbodycontinuous.png
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    thank you, this seems to work now. i'm pretty sure it didn't when i last tested
     
    BrandyStarbrite likes this.
  4. Abhinav91

    Abhinav91

    Joined:
    Oct 21, 2013
    Posts:
    67
    If it's two Dynamic Colliders, you have to set one of the object's Rigidbody Collision Detection to Continuous, and the other object's Rigidbody Collision Detection to Continuous Continuous Dynamic.
    If it's one Static Collider and one Dynamic Collider, set the object's Rigidbody Collision Detection to Continuous.

    PS: Static Collider means a GameObject without a Rigidbody. Dynamic Collider means a GameObject with a Rigidbody.

    It's worth noting that Continuous and Continuous Dynamic collision detection modes have an impact on the Physics performance.

    Hope this helps.
     
  5. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    1,156
    Wooah! This was informative.
     
    Deeeds likes this.
  6. deletemyaccountplease111111

    deletemyaccountplease111111

    Joined:
    Nov 28, 2018
    Posts:
    1
    I know this is an old thread, but I had this problem and it drove me insane. So here is what solved it for me: If a collider has the isTrigger boolean as true, it will not interact with other collider's physics. In other words, if a collider is a trigger, it will raise whatever flag is required for the OnTriggerEnter function, but will not "push" the other collider away and it will not be pushed back.

    TL;DR: Set your collider parameter isTrigger to false or add another collider component that is not a trigger
    Finish the tutorials, kids. They're that long for a reason.
     
    Deleted User likes this.
  7. domangorilla

    domangorilla

    Joined:
    Sep 13, 2017
    Posts:
    4
    How would this apply to detecting collisions on a part of an animation? I have a similar problem as OP does, but instead of a high-speed physics projectile, it's a fast moving sword. In one frame of the swing, the sword has not yet collided with the other sword, but in the next frame, it is already past the sword. Though there are continuous kinematic rigidbody trigger colliders on both swords, I imagine this does very little if the movement of the swords is through an animation instead of the physics engine.

    I have more details here: https://forum.unity.com/threads/parryable-attack-animation.590581/
     
  8. cardcastleusa

    cardcastleusa

    Joined:
    Mar 20, 2018
    Posts:
    6

    That is true, at this point you will want to use a Raycasting system that extends out of your sword, Since update goes once per frame you could always add the sword swing raycast into a Coroutine and have it occur as often as you'd like.
     
  9. CRYWOLF86

    CRYWOLF86

    Joined:
    Jul 23, 2016
    Posts:
    11
    If you want physics to apply to your sword, I recommend having your sword as a separate physics game object. You can then use rgidbody.moveposition and rigidbody.moverotation to interpolate it to your animation source.

    My swords detect each other, but still, have a problem of "popping through" each other.
     
  10. Abdul256

    Abdul256

    Joined:
    Aug 17, 2019
    Posts:
    1
    ..........
    Thank you for this help