How to stop two colliders from pushing each ohter

That’s an old question,but I haven’t found any way to solve it.
In Unity,colliders with rigidbodys will push each ohther because of the force of physics.
But in some cases,we just need they stop moving when they collide,just like you and your friend can’t push each other in Dark Souls,CS,and so on.
The collider just be like a wall to another collider.
Indeed,if we set Collider-A to Kinematic,Collider-B will not push Collider-A.But the Collider-A still can push Collider-B.

So,are there any way to solve it?

Sorry for my SUCK English,not my mother tongue.

Isn't it possible to use an OnCollision and get the direction vector towards the object it collided with? (Vector3D collisionDirection = Collision.gameObject.transform.position - transform.position;) Then just make sure this vector is >= 0 in the rest of the movements until the collision no longer exists.

2 Answers

2

Try in your on collide:

 rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;

this freezes the positions, so It wont move.

NOTE: to unfreeze use:

rigidbody.constraints = RigidbodyConstraints.None;

Hope this works for you!

As you say - in real-life, when two rigidbodies collide, they both exert a force on each other.
If a car hits me, the force that the car applies to me will knock me over, but I’ll also exert a force back on the car. That force doesn’t cause the car to go flying backward because the car has a much greater mass.
If I head a football, my head recoils a little bit, but the football goes flying away because it has a much lighter mass.

So, in other words, you need to make the mass of the objects that you don’t want to be pushed much greater.

thanks for the answer. But I don't think my fat friends in game should push me. I want all objects can't be pushed.

You are welcome ^^. I'm glad if I was of some help.