Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback DOTSPhysics features I wish I had in monobehaviour physics (PhysX)

Discussion in 'Physics' started by PhilSA, Feb 12, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    There are a few features in DOTS physics that are either very useful or crucial for implementing things like character controllers, and I was wondering if there was a possibility to make the PhysX integration have those features too:
    1. The ability for "castAll" queries (like SphereCastAll) to detect one hit per triangle in a non-convex collider, instead of just the closest hit for each hit collider. The justification for this one would be too long and drawn-out to explain, but the short version is that I can't make robust and reliable character ground detection without having that feature
    2. We would need some equivalent of Physics.ComputePenetration() that also gives us accurate contact position information; not just the normal. In DOTS physics, "CalculateDistance()" gives us that info. Note: just like point #1, this "CalculateDistance()" should also give us all triangle hits in non-convex mesh colliders
    3. The ability for cast queries to properly detect initially-overlapping hit information. Right now, when you do a SphereCast that starts out already overlapping with another collider, the hit information is not properly detected (hit.point is zero, hit.normal is up). "CastCollider" in DOTS Physics is able to give us both the point and normal of initial overlaps
    4. Having a "Physics.CastCollider()", and a "CastColliderAll()" variant: similar to a sphereCast/boxCast/etc... but it takes a collider as input. I think Rigidbody.SweepTestAll() is somewhat similar, but it is unusable in real projects due to having no NonAlloc version. Currently, without this, I would have no way of creating a cylinder-shaped character
    It's been a while since I've used monobehaviour physics, so let me know if some of those things are actually possible now or if some of my assumptions are wrong
     
    Last edited: Jan 14, 2022
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Here's my attempt to explain why point #1 is so important:


    Consider this green non-convex collider and this blue character capsule. A Character Controller will typically want to detect grounding by doing a downward CapsuleCast (or SphereCast). But since physics casts only detect one hit per collider, sometimes when our character capsule is very close to the wall or if our wall has a very slight angle, our ground check will decide to detect the wall hit (purple) instead of the ground hit (red). This causes my character to "unground" itself once in a while when moving against walls, because it didn't get a chance to detect the true ground hit

    Techniques such as "skin width" can help mitigate this problem, but it isn't fail-proof and creates all kinds of other difficulties too. Same goes for trying to do additional raycasts or offsets for ground detection

    Having physics queries that detect ALL hit triangles would let me filter the hits to find the true ground hit
     
    Last edited: Jan 12, 2022
    apkdev, one_one, Blueprinter and 3 others like this.
  3. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    931
    This point has been the biggest pain point for me till now, as it requires a lot of workarounds using skin width and casting from a position behind actual spherecast point, etc. :(
     
    Gooren likes this.