Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Collision detected 'close' to collider, dependent on projectile speed.

Discussion in 'Physics for ECS' started by Shinyclef, Mar 31, 2021.

  1. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    Hello,

    In the following picture, on the left is a box with a static collider. To the right of it, I have shot a projectile, it has a small sphere collider (radius 0.078). It has gone past the box as expected.
    upload_2021-4-1_0-50-16.png

    For debugging purposes, every time I shoot, I set a random projectile speed between 20 and 200.
    When a have a slow moving projectile, it does not collide like in the picture.
    However, when the projectile is moving fast, e.g. a velocity magnitude of like 100 to 200, with the exact same aim, the projectile collides with the box.

    My physics step is set to 1/30, but theoretically this shouldn't matter I believe.
    Any idea what's going on? This a bug with fast object collision detection?

    Cheers.
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Faster bodies have a larger AABB (the bounding box is expanded by the velocity). With a larger AABB you are more likely to overlap with other bodies.
    When you say the fast moving body 'collides' I can understand that a contact point would be created from the overlapping pair but are you getting a deflection?
    On a side note, a sphere projectile that size probably suggests a raycast implementation rather than bothering with a full body?
     
  3. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    You're right, I should use raycast. I'll eventually use larger projectiles too though.

    I'm not sure about a deflection, but the collision event triggers depending to projectile speed and I destroy the entity. I think i see a single frame of deflection though.

    I am using collisions rather than triggers as it seems to handle high speed better. However I will switch to raycasts.

    Edit. I'm probably wrong about this. I might be colliding with player collider. I can't test though as I've already changed a lot of the code to raycasts!
     
    Last edited: Apr 1, 2021
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    The bounding box of a body is expanded by the velocity of the body. Faster bodies will have a bigger bounding box so that it will pick up collision pairs with more bodies. This expansion is calculated by the MotionVelocity.CalculateExpansion function in com.unity.physics\Unity.Physics\Dynamics\Motion\Motion.cs.
    I suspect that if you tweak that function in a local copy of the Unity Physics package setting Linear and Uniform to 0.0f the speed will no longer matter, and you won't get collisions from fast moving projectiles. At the same time you will be changing the physics engine to work as a discrete rather than continuous simulation and bullet through paper issues will start appearing instead - details of the difference are documented here.
     
    Last edited: Apr 6, 2021
    Shinyclef likes this.