"Dodgy" Mesh Collision with Rigidbody

I don’t think this has anything to do with my character controller, but I have included that at the bottom in case it is causing this.

On the inverse corners of my map (the acute 90-degree angle INSIDE a box), if I continuously push against them and look around a bit I clip through it pretty violently.

I wouldn’t have even noticed had I not tried to use my staircase (a stairwell encased in a long vertical rectangular tube) as once I try to go up it fast and hit a corner on the way up I go straight through it with little to no effort and end up falling forever.

I am using a mesh collider as the stairwell as 2 doorways, 1 at the top and 1 at the bottom which meant I can’t use a box collider for obvious reasons.

Why is the collision in Unity so dodgy and not in other engines, despite them all using PhysX? And is there any way to fix this? Flying through walls while going up a flight of stairs is a pretty show-stopping issue…

As promised…my controller, just in case:

/*
* ---- Character Controller: Character Movement ----
*
* To Add:
*      Smoother Movement
*      Better Collision w/ Movement
*      Setup as Static to Save Settings
* */

using UnityEngine;

public class CharacterController : MonoBehaviour
{

    public static CharacterController playerController;

    public float speed = 10.0f;

    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    void Update()
    {
        if (!PlayerControl.playerControl.isPaused)
        {
            if (Input.anyKeyDown)
            {
                Cursor.lockState = CursorLockMode.Locked;
            }

            float translation = Input.GetAxis("Vertical") * speed;
            float straffe = Input.GetAxis("Horizontal") * speed;
            translation *= Time.deltaTime;
            straffe *= Time.deltaTime;

            Vector3 moveDir = new Vector3(straffe, 0, translation);
            moveDir = transform.TransformDirection(moveDir);
            GetComponent<Rigidbody>().MovePosition(transform.position + moveDir);

            if (Input.GetKeyDown(PlayerControl.playerControl.pauseKey))
            {
                Cursor.lockState = CursorLockMode.None;
            }
        }
    }
}

The PlayerControl stuff is just a static class holding control schemes.

It likely is your call to GetComponent().MovePosition(transform.position + moveDir);
It will mostly bypass the rigid bodies collision resolution.
You may be able to get away with setting the velocity of the Rigidbody directly. That should help it resolve collisions at the intersections of props.

Generally though you should be using AddForce() on the rigid body instead as that will allow it to void penetrating objects.
Also you should be setting forces on the rigid body inside void FixedUpdate() instead of void Update() on the MonoBehavior as FixedUpdate() is always called just before the rigid body is simulated.

putting it in FixedUpdate would be a good start.

Try to avoid doing physics stuff in Update

Sorry for the late reply, had a few scripts die on me over the last week or so.

I have tried a few things to counteract this including:

GetComponent<Rigidbody>().AddForce(moveDir);
GetComponent<Rigidbody>().AddForce(transform.position + moveDir);

Neither of which worked, and left me unable to control the character.

Is there something different I need to be doing with Force to use it in the same way as MovePosition?

Bump