Search Unity

Question CharacterController like Snowboarding - Collision Queries "don't" work

Discussion in 'Physics for ECS' started by RichardWepner, Jul 31, 2022.

  1. RichardWepner

    RichardWepner

    Joined:
    May 29, 2013
    Posts:
    33
    TL;DR: What can I do with the following problems? (Colliders generated via code)
    - point distance and overlap checks miss some collider completely
    - SphereCast(All) collides immediately with the ground while attempting a "sweep"
    - SphereCastAll finds multiple collisions with the same collider (different sides of the collider)


    For a project of mine, I'm trying to implement a snowboarding mechanic, i. e. sliding down a track. With any approach I tried I had different kinds of problems.

    On the one hand, using the regular physics simulation causes the player to lift off the ground to much, and I'm not so certain about how this could be addressed in the DOTS Physics. In order to have more control about how this works (and since I don't need a general purpose physics simulation, and since it is supposed to also work well as networked game), I decided against pursuing a path with regular physics simulations.

    The alternative is doing the simulation part manually (similar to how most Character Controllers work) using casts (ray, sphere, ...), overlap checks, or distance checks. I tried several things here, but all of them with different problems:
    - `SphereCast` and `SphereCastAll` immediately collide with the environment, even though the cast direction is (or should be) parallel to the ground.
    - `SphereCastAll` also collides the the "walls" between the segments, which lets the character believe to be on a flat ground (since the "wall" is below the character).
    - Adjusting the cast by reducing the size causes the character to clip into walls/the ground.
    - Adjusting the cast by starting it above the ground causes the casts at a wall downwards to immediately collide with the wall, but with an offset upwards, causing the character to not just stick to the wall, but also to slide it upwards.
    - Doing a RayCast first and then an overlap or distance check would technically lead to "wrong" results (the acceleration/decelleration might be a bit to large/a bit to small), but this should be ok. But: Overlap and Distance checks don't seem to find certain parts of the environment, causing the character to sink into the ground and to get stuck in front of the next "visible" collider that's picked up the the ray cast again.

    How could I approach this in order to finally overcome this problem?

    I decided to give DOTS and Netcode for DOTS a try, because they (in theory) bring some big advantages for implementing a networked multiplayer. Reverting to an old state (e. g. received from the server) and repeating the simulation steps up until the current state is easy to do, to name one example, or the easily achievable multi-threading, combined with the performance gains from Burst.
    Yes, all those packages are preview packages, but I was hoping not to run into (in my case) so big problems so early on during the development. This really frustrates and steals the motivation to continue to work with this technology stack, even though it already has advantages to offer.