# Unity: Disable push on dynamic Rigidbody2D objects

I have a player, and several NPCs. I also have several static colliders in the world (trees, water, fence, etc), I want my NPCs to collide with this, so the Rigidbody2D needs to be dynamic, since kinematic does not collide with static colliders (colliders without a rigidbody).

My problem is that since both player and NPC have dynamic rigidbodies, they push each other when they collide. I could disable this by setting the following in the NPC script:

void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.name == "Player") {
isMoving = false;
myRigidBody.isKinematic = true;
}
}


However, the NPC still gets pushed a few pixels before it stops, its barely noticable, but it is noticable, and if you keep colliding with the NPC you could move it as far as you wanted (tedious, but possible).

I've spent a few hours looking and cannot find a good solution to this. I want my NPC to collide with static colliders, but I don't want them to get pushed by the player. How can I solve this?

• Do you want your player to collide with NPCs or just go through them? – John Hamilton Jun 9 '17 at 16:56
• @JohnHamilton Collide, hence the issue :) Otherwise Id just ignore its Layer – Majs Jun 9 '17 at 17:25
• Do you want the NPC to be affected by any other objects? – ChargerIIC Jun 9 '17 at 20:59

• Can you explain to me how this works? I create a child GameObject of my NPC, I attach a Collider2D to it and set it to trigger. I can now add the OnTriggerEnter2D() to a Script attached to my NPC, and it works? How does it know that I want to use the collider from the child object? Since that one is a trigger and the one on the NPC is not? – Majs Jun 9 '17 at 20:39
• Btw it works, just wonder how/why it works. Shouldnt I have to attach a Script to the child where I check OnTriggerEnter2D? – Majs Jun 9 '17 at 20:40