Why the npc keep walking through the door/s after added to it a box collider and a rigidbody?

The player can’t walk through the door/s but the npc can.

Screenshot of the Npc and it’s inspector settings.

You have set your object’s rigidbody to be kinematic, which means forces, collisions or joints will not affect the rigidbody anymore, but the kinematic body can affect other rigidbodies if they collide. So if you move your npc with code, it will go through walls etc. as nothing in physics is stopping it. If you want to use kinematic rigidbodies, you have to decide how you detect collisions and stop your agent/npc from moving and so on. Maybe use a trigger to detect collision and then stop.

1 Like

If I’m not using kinematic the npc falling forward then walking on place facing the floor.
So I guess I will have to use a code with trigger. But I still wonder why without using kinematic it’s not working and what should I do to make it work fine.

Uncheck the trigger and Kinematic properties and use OnCollisionEnter

Edit: Oh sorry. I missunderstood your problem…

Judging by your Rigidbody window you’re not using any Constraints. You can either enter them manually in the Rigidbody’s Editor window or…

//A Rigidbody's Constraints must all be coded at once. Use '|' to add additional constraints

rigidbody = GetComponent<Rigidbody>();

rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;

The reason why your character falls over is because of the lack of Rigidbody rotation constraints. With that being said do keep in mind that turning usually happens on the Y axis.

Whilst its good and there’s nothing wrong with adding useful information to any post, when replying to someone directly, please try to look at the dates of posts. This post was from 2019.