Make rigidbody ignore collisions from Physics.IgnoreCollision

I have a platformer game, and I am achieving the effects of one-way platforms by using Triggers to disable collisions between a platform and the player using Physics.IgnoreCollision. If I just use the PlayerController for collisions, the process works fine, but if I give the player a Rigidbody, I get some unexpected results.

Whenever the player jumps up from below, after getting about halfway through, the Rigidbody pops them up the rest of the way until the bottom of the player is flush with the platform. It doesn’t reset the vertical speed, though, so they then continue their jump from there, effectively getting a boost of half their height when jumping through a pass-through platform.

Here’s the code that calls ignoreCollision:

void OnTriggerEnter(Collider other)
    {
        if (other.tag == "PassThrough")
        {
            Physics.IgnoreCollision(GetComponent<CharacterController>(), other.transform.parent.GetComponent<Collider>(), true);
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (other.tag == "PassThrough")
        {
            Physics.IgnoreCollision(GetComponent<CharacterController>(), other.transform.parent.GetComponent<Collider>(), false);
        }
    }

This script is attached to a character to give it the ability to jump through platforms (triggers with the “PassThrough” tag that are children of a platform). I’ve swapped the GetComponent CharacterController with Collider and Rigidbody to no effect.

OnCollisionEnter is basically run after the physics system processes the collision… so the ignore collision is kicking in one frame late.

The OnCollisionEnter is on a trigger, separate from the actual colliding platform, so it should be hitting the trigger well before the collision actually happens. I was aware of the one-frame delay so I made the trigger bigger than the collideable area of the parent platform.

Are you sure its hitting a full frame before the collision happens? I’ve had issues with triggers as continous dynamic collision does not have the same effect with them as it does with actual colliers.

Also is CharacterController a collider? I think you need to pass in the collider directly.

I’m 100% certain that the pass-through trigger is more than a frame away. The trigger extends all the way to the ground below it, and the player doesn’t even touch the platform until they’ve double-jumped.

CharacterController is a collider, I get exactly the functionality I’m looking for as long as the player doesn’t have a Rigidbody attached.

Sounds like they have yet another bug in this system. There is another thread in this section about physics.ignorecollision not working. I tested this for them back in the beta for 5.5 and it was working then but have not converted my assets over to use this since. Not great news.

If it helps figure out what’s going on, or what a workaround could be here’s a comparison:

Here’s the collision without a rigidbody: https://gfycat.com/FatalRealGermanshepherd
And here it is with the exact same input, but a rigidbody added: https://gfycat.com/DeepFragrantBilby

It’s technically ignoring the collision, but it’s popping the collider up to the top of the platform as soon as it’s halfway through.