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?