- Home /
Can I change the order that collision layers collide with each other?
I have a weapon script checks for the following in OnCollisionEnter:
If the weapon collided with something in the Character layer, do damage
If the weapon collided with another weapon in the Item layer, disable the ability to damage the owner of that weapon for x seconds (to simulate getting blocked)
The problem I'm having is when a weapon collides with another weapon and a character on the same frame, OnCollisionEnter will happen with the character before the weapon. This causes the character to take damage and block the attack in the same frame. If OnCollisionEnter was getting called for the weapon first I would not be having this problem. Is there any way to change the order the collision layers gets checked?
This is my collision matrix:
Answer by jstopyraIGG · Feb 28, 2019 at 12:23 AM
I suggest having the character take damage in LateUpdate. So in your collision, you can set a bool, or some other state, "Attacked", and "Blocked" and in LateUpdate, you check if its blocked first, then block, if not then check if attacked, if attacked then take damage.