I'm developing a network game. Players and enemies have attached
Rigidbodies, move with physics forces, stops on kinematic colliders (walls) - everything works pretty well. Now it's the time for player-player and player-monster coliisions.
In my case, the player should be unpushable, even by other players and monsters.
The problem with that is if all 'moving/non-kinematic' objects have rigidbodies, they can move/push each other as they move - which is wrong in my case. I came up with an idea that I'll disable collisions between these objects through layers and did that.
I also wrote a script which pushes the object back (in the opposite direction) when triggered which I want to apply.
The problem is here, that I need to preserve the original collider (non-trigger) so the player can be stopped by walls AND I need to detect other players in
OnTriggerEnter() so I can push them back so they don't overlap.
This is quite easy - I need two colliders attached to the player:
a non-trigger one - responsible for the ground, walls, physics driven
a trigger one - for interaction with players and enemies (to push them)
I also need to disable built-in collisions between players through the physics layers and listen for
"Monster" tags in
Does this all make sense? How would you improve this? Is there a quicker way to achieve this? Two colliders seem not that bad - but it's still two instead of one.
In order to visualize what I want to achieve:
Games I know have collisions like this are
Diablo 3 and
League of Legends probably.