# 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? Feb 24 '15 at 15:07
• @fryBender we are using transform.position Feb 24 '15 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. Feb 25 '15 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
Jan 13 at 14:34
• It should work now.
– DarQ
Jan 13 at 16:45