- Home /
Set player and enemy RigidBodies so that neither can push the other
I want to set up my RigidBodies such that my player and all enemies cannot move each other when interact. Right now, my player cannot be moved by enemies, but he can push enemies around very easily, as seen in this gif below:
https://gfycat.com/acclaimedsilvergopher
Right now, my game is set up such that both the player and the enemies have Dynamic RigidBodies, and the player has a mass of 10,000 while enemies have a mass of 1; thus, the player can push around the enemies but not vice versa.
I tried reversing the the masses such that it is the enemy who has a mass of 10,000 and then creating a script where the enemy will stop once it gets within a certain distance of the player, but when there are multiple enemies they end up pushing on each other and then pushing the player because. Writing a script to account for this becomes complicated.
Is there anyway to set up RigidBodies such that two Dynamic objects cannot push each other at all? Thanks!
Answer by SecretAgentMango · Oct 19, 2021 at 01:33 AM
This man has all the answers: https://www.youtube.com/watch?v=-yjKyI8NfKA
Just use 2D colliders and physics instead :)
Answer by tfalmeida91 · Oct 19, 2021 at 02:05 AM
Hi there. Yes there is!
You can create a bunch of Layers, and in the Physics Settings, under Edit > Project Settings > Physics, under Layer Collision Matrix, you can select wich layer interacts with another.
This way, you can have two (or any number you wish) Rigidbodies with colliders that won't react with eachother, including Triggers.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Deteriorating force on object? 0 Answers
Distribute terrain in zones 3 Answers
unity2d change angular direction 1 Answer