How to disable push force between two rigidbodies?

Hi, I’m working on a game project. Character objects have rigidbody + capsule collider. They move with velocity, but I don’t want them to push each other. Just like in this video

the ways I tried so far:

  • giving “.isKinematic = true” to objects when they collide (OnCollisionEnter)

  • changed enemy characters’ rigidbody mass. with this way player can’t push its enemies but enemies can :confused:

Is this possible with Unity?

I found the solution here

@omermecitoglu Can u explain how this solved it for you? Wouldn’t ignore collision just make them pass right through each other as if they were non-existent?

1 Like

Sorry to necropost, but after fiddling with this problem for a good 3 hours I figured out what the other thread meant and it works perfectly. So what I did was I had a parent object with a non-trigger collider and a dynamic rigidbody. I then added a child to this object with a non-triggercollider that is slightly larger than the parent collider and added a kinetic rigidbody to the child object. In order for the parent and child non-trigger colliders to no collide, you set IgnoreCollision(parentcollider, childcollider) in a start method.

The behavior of multiple objects with this setup is that they no longer push eachother, since when one object tries to push the other, he will enter the kinetic collider of the other with his own dynamic collider, which it cant push and vice versa. I hope this clears things up for you.

3 Likes

Hi @CamargoNL ,

Thanks for sharing. Yeah we solved it exactly like this back then, but never shared it here. But good you did for other people that stumble across this in the future. It’s actually super simple, but it took me a good time to figure it out. Our exact solution (maybe it’s helpful for others):

First collider:
5648806--587272--upload_2020-3-30_17-20-19.png

Second collider (child object of Player): Only let this collider collide with objects of layer Player
5648806--587275--upload_2020-3-30_17-20-48.png

To prevent it from colliding with it’s own playerblocker:

Physics.IgnoreCollision(PlayerCollider, PlayerBlockerCollider, true);
7 Likes

My solution was similar to the @Leniaal 's, although:

  • I didn’t find it necessary to add the script – there wasn’t an issue with the two colliders colliding in my case.
  • I set the parent collider (the RigidBody) Layer to not collide with other RB colliders and the child collider Layer to collide with other RBs.
  • I set the Mass of the other RBs higher (and played with the Drag and AngularDrag), although, honestly, some pushing felt good.

Not the most elegant solution, but it works.

Wow, Thanks your reply, I find the resolution for a long time, the method is very good!

Thanks for your reply it is very informative