Hello!
The question of universal and simple forcefield mechanics is bothering me for years.
Imagine forcefield. It can stop enemy projectiles and lasers (in other words, it is interacting with colliders and raycasts), but allies can shoot through it.
Corrently, i have used 2 different solutions:
- two layer masks - one for allies and one for enemies. Forcefields have layers ForceField_Team1 and ForceField_Team2 Each projetile/raycast can interact only with forcefield with layer of opposite team (projectile of Team0 can interact with forcefield of Team1 and vice versa).
Pros: relatively fast
Cons: layers count must be equal to team count. If there are more than 2 teams, things get more complicated. - team id check logic. Forcefield gets a script containing team id. Each projectile checks every collision, and passes through forcefield if its team id equal to that projectile. Each raycast transforms to RaycastAll and checks every hit to determine if forcefield is hitted and if it is enemy forcefield.
So the question is, is there another, more elegant way to deal with force fields and teams?
Thanks