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

Question DOTS Physics fast moving objects collide before touching other objects.

Discussion in 'Entity Component System' started by aducceschi, Jul 21, 2022.

  1. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Hi,

    I have a ball and a surface that are both entities using the new DOTS Physics Package.

    When the ball moves fast (more or less the same speed as when you throw a ball with your hand),
    the ball collides with the surface around 20 cm (0.656168 ft) before touching the surface and bounces back.

    This only happens if it moves fast.

    Does anyone know how can I change this behaviour or at least reduce it?

    Thank you.

    EDIT: I have found a float called CollisionTolerance by doing this:
    World.DefaultGameObjectInjectionWorld.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld.CollisionWorld.CollisionTolerance;

    Unfortunately it says its read only and I can't reassign it. I tried to create a new Collision World and the replace the current world with the new one but to no avail. I can't even change the value on the new world. Any ideas?
     
    Last edited: Jul 21, 2022
  2. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    You might get more likely an answer if you post it in the DOTSPhysics sub-forum, as it’s mainly related to that subject.
     
    aducceschi likes this.
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I'd guess that this is due to continuous collision detection (CCD), which comes by default in DOTS physics. When a rigidbody moves fast, the physics engine needs to speculate a little bit about what it might come in contact with over the next simulation step, and this can cause imprecisions in collision reaction. The alternative, if CCD was removed, would be that your fast rigidbody would probably go right through certain colliders. So CCD is kinda like the "least bad" option we have in physics engines.

    It's the natural consequence of not having infinitely-powerful CPUs that can simulate an infinite amount of physics steps per second. Right now we have to make do with around 60 steps per second if we want reasonable performance in most cases, but you could still try to increase that amount if you want

    If your use case is something like a weapon projectile, you might want to consider an approach where instead of making your bullets rigidbodies, you'd handle collisions manually using raycasts or spherecasts. Here's an example of such a system:
    https://forum.unity.com/threads/bullet-hit-detection-strategies-performance.930015/#post-8083187

    But if you definitely need it to be a rigidbody that dynamically interacts with other rigidbodies, I'm afraid I couldn't think of a solution at the moment. It might be worth giving Havok a try and see if it has higher-quality CCD
     
    Last edited: Jul 21, 2022
    aducceschi likes this.
  4. aducceschi

    aducceschi

    Joined:
    Feb 9, 2022
    Posts:
    39
    Thanks! I tried already tried to increase it to 360 steps per second (up from 180), but unfortunately it didn't make a difference.