Player can fall through the ground under certain conditions

Fenda

Member
Justin - I believe you're working on the multiplayer add-on so would like to hear your thoughts on this! Especially in regards to how you plan to approach it.

Problem: Player gets squashed between 2 game objects and then eventually falls through the ground.

Demo: See the GIF below. You can see that this happens in my game when I stand behind one Player (we're both the same prefab, so the same rigidbody mass) and then close a door in their face.

Potential solution: Setting Continuous Speculative mode for the collision detection mode seems to alleviate the issue but will that break anything else with UCC? Do you think that's the correct way to approach this?
 
When the doors are closing the character doesn't have anywhere to go so Physics.ComputePenetration tries to determine a location that minimizes the collisions. It should only move the collider horizontally though, and not push the character down. Are you able to put a small repro scene together so I can take a closer look at what is going on?

Also, does Continuous Speculative fix it? I'm kind of surprised that it does because the controller doesn't use rigidbody physics.
 
I also have encountered this issue with a double door setup similar to the one that @Fenda has.

According to the Unity documentation Continuous Speculative mode does work on both kinematic and dynamic rigidbodies, but since UCC handles its own collision detection I don't think Continuous Speculative mode will fix the cause of the issue.

In any case, it is possible for a UCC character to get stuck between two dynamic rigidbodies. The only way that the character becomes unstuck is to either temporarily disable horizontal collisions (not a good solution) or for the character to eventually fall through the ground.

I will try to create a repro scene in a clean project and upload it.

Edit:

I have uploaded a repro scene.


A work around is to apply this script to both doors:

C#:
    [RequireComponent(typeof(Rigidbody))]
    public class ConstantCollisionForceRecipient : MonoBehaviour
    {
        [SerializeField]
        protected float forceMultiplier = 2f;

        [SerializeField]
        protected ForceMode forceMode = ForceMode.VelocityChange;

        protected new Rigidbody rigidbody;

        protected virtual void Awake()
        {
            rigidbody = GetComponent<Rigidbody>();
        }

        protected virtual void OnCollisionStay(Collision collision)
        {
            var dir = (transform.position - collision.transform.position).normalized;

            var force = dir * forceMultiplier;

            rigidbody.AddForceAtPosition(force, collision.transform.position, forceMode);
        }
    }

This work around simply prevents the conditions where the player is stuck from ever occurring. That being said I think a more robust solution for when a character is stuck needs to be developed.
 

Attachments

  • StuckRepro.zip
    122.7 KB · Views: 2
Last edited:
I just tried your sample scene but wasn't able to reproduce the character getting stuck. I tried various methods of going through both set of double doors. Is there a particular area that the character always gets stuck in?
 
I just tried your sample scene but wasn't able to reproduce the character getting stuck. I tried various methods of going through both set of double doors. Is there a particular area that the character always gets stuck in?

This has been tested in 2019.1.3f1. Nolan gets stuck at (-0.1258323, 0.050002, 2.447401). I am attaching an automated scene that gets Nolan stuck. You will need to attach the GetPlayerStuck script included in the zip to the Target Position gameobject and then go into play mode.


Nolan stuck 2.png

Nolan stuck 1.png
 

Attachments

  • AutoStuckRepro.zip
    123.3 KB · Views: 2
Thanks for that repro scene. It looks like as the door slides back into place it is slightly overlapping with the character controller and this is getting the character stuck. I tested a quick idea on how to fix this but because it is collision related I am always more careful with the changes. I need to do a lot more testing and if it ends up being a quick change I'll post it here otherwise it'll be in the next version.
 
I wasn't able to play your demo scene because of the compiler errors so it's tough to say but I wouldn't have expected the character to completely fall through the ground with the collisions. What I am fixing helps with detecting new objects if there is a collider already overlapping the character.
 
Top