- Home /
Rigidbody2D characters push each other
I'm currently working on a top-down multiplayer game. I'm pretty happy with how my networking code is coming along, but I don't like how it behaves when two players collide - the movement and prediction gets very choppy as the two Rigidbody2D characters try to push each other around.
After some deliberation, I've decided that I just don't want them to push each other - I'd rather just have another player act as a wall that blocks your progress. You can't move any closer towards them and they can't move towards you. Unfortunately, I don't see a simple way to do this. You'd think it'd be built into the physics engine, but it's starting to look like I'll have to integrate a custom movement system to do this.
If anyone sees a simple solution to this, please do spare me the pain of working around the built-in physics to make this work.
You could use Triggers to make it much easier than rewriting the collision altogether. Another option would be to wait for OnCollisionEnter and then calculate the direction towards the colliding object and prevent the player from moving in that direction using a bool toggle.
Turn on Trigger, Then if you want a object to hit into it you can use a code like this one
function OnTriggerEnter2D (other : Collider2D)
{
}