# How to stop objects pushing each other away on collision?

I'm creating something along the lines of Super Smash Brothers. There's a problem with the collision between the two players and projectiles.

We have rigid body on the characters and projectiles and every time they collide they push one another back, I know that is how it operates but is there a way to stop that from happening?

• How are you moving the game objects? Are you setting their velocity or adding forces to them? Commented Feb 24, 2015 at 15:07
• @fryBender we are using transform.position Commented Feb 24, 2015 at 15:12
• If you set the projectile's Collider to "Trigger" then it will still detect collisions (using OnTriggerEnter instead of OnCollisionEnter), but will not push objects with which it collides. Commented Feb 25, 2015 at 4:17

Set the mass of your projectiles to be very low, and the mass of your characters to be higher until they are no longer affected by the collision of the projectile (mass is a variable on rigidbody component).

The reason your rigidbody's push each other away is because this is what physical objects do in real life and rigidbody simulates this as accurately as possible. You throw a light ball at a heavier ball, both balls react. The heavier ball moves less than the lighter ball. If it was a really heavy ball, or a rock I guess, the really heavy ball/rock wouldn't move noticeably.

This will work if you're expecting your projectile to be destroyed on hit like Mario's fireball. If you want to use a beam or something like some of the final smashes, you'd make the beams "hitbox" (http://en.wikipedia.org/wiki/Hitbox) a trigger that exists for one FixedUpdate frame and deals its damage/applies its forces and then goes away the next frame.

Also, when moving rigidbody's, do so via rigidbody.AddForce or add to its velocity yourself, as setting the transforms bypass the physics simulation and can easily result in you moving your objects into one another and cause them to become stuck. AddForce is more realistic at times, and just adding to the velocity can be easier to use at sometimes.

This is easy for a platformer, example in FixedUpdate:

if(rigidbody.velocity.x < maxMoveSpeed) { //and pressing right
//apply force right
}
if(rigidbody.velocity.x > -maxMoveSpeed) { //and pressing left
//apply force left
}


you can create two GameObjects one with a collider and one with a Rigidbody. link the position of the one with a collider with that of the one with a Rigidbody. Now both can move with physics without interacting with other gameObjects. Use the one with a collider for collision detection and such.

• I was thinking of doing that in OnCollisionEnter as in doing what you want the bullet to do but I tested it and it seems for a few frames they can still interact with each other so I'm working on it
– DarQ
Commented Jan 13, 2021 at 14:34
• It should work now.
– DarQ
Commented Jan 13, 2021 at 16:45
• Thanks for updating your answer :) Commented Jan 13, 2021 at 16:48

In your comment you mentioned that you are setting the game objects positions instead of relying on forces or velocity. If I had to take a guess, the problem you are facing is having two rigidbodies colliding together, which in turn is affecting other rigid bodies. You have two options in this case

1. Remove the rigidbodies altogether. If you are not using velocity or forces to move your bodies, why attach a rigid body?

2. Set your rigidbodies to kinematic. This way you'll leave your options open in case you do decide to have objects in your scene that can be affected by physics

Further Information on Kinematic Rigidbodies

To enable kinematics on a rigidbody all you have to do is click on the checkbox labelled "isKinematic". Kinematic rigidbodies are not affected by forces, gravity or collisions. They are explicitly set by setting the position and the rotation of the game object, however they can interact with other non-kinematic bodies.

• reddit.com/r/Unity3D/comments/1d3ma9/… "Objects without a rigid body are considered motionless by Unity, and if they have colliders they get sorted into a high performance scene graph, which greatly increases the physics performance. However, every time you move one of these objects, the graph has to be recalculated, This is slow, and should be avoided if you can help it. Having to rebuild the graph every frame will cripple your performance." Commented Feb 25, 2015 at 5:57