When invoking Physics.IgnoreCollision in Unity, it seems work but it still have collision detection right after creation.
I have this issue with ejecting empty case after gun fire, it's spawning position located inside of character controller(collider), so when ejecting case created, it immediately hit to my character controller and makes my character slows.
First I thought that it's coming from something else, but it's not, because when I just not spawning the empty case, it never happens.
This is the code:
GameObject ejectedCase = Instantiate(emptyCasePrefab, caseSpawnPoint.position, caseSpawnPoint.rotation);
Collider caseCollider = ejectedCase.GetComponent<Collider>();
Physics.IgnoreCollision(caseCollider, playerCollider);
Note that playerCollider is Collider. I also tried with CharacterController(because it's extended from Collider class) but result was same.
Why I said something like "it's not working right after invoked" because it's actually working after passed some time. If it's not work, character controller step on the empty case and makes camera jittering issue on vertical axis. This is totally gone after ignoring collision detection with above code, however it still works right after creation and makes my character really slow.
How do I avoid this weird glitch, makes IgnoreCollision works right after it invokes?
In addition: I don't want to fix this issue with using Layer Collision Matrix. I didn't tried but it will work sure, however I don't want to spend Layer for this purpose only, because it's number is limited and already using lots of layers in other logics so it makes game logic more complicated if I use Layer to avoid collision detection. I want to know why "Physics.IgnoreCollision" not works because literally it saids "ignore collision" but it wasn't.