Search Unity

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

Discussion in 'Physics' started by DubiDuboni, Oct 25, 2019.

  1. DubiDuboni

    DubiDuboni

    Joined:
    Feb 5, 2019
    Posts:
    131
    The player can't walk through the door/s but the npc can.

    Screenshot of the Npc and it's inspector settings.

     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    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.
     
    DubiDuboni likes this.
  3. DubiDuboni

    DubiDuboni

    Joined:
    Feb 5, 2019
    Posts:
    131
    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.

     
  4. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257
    Uncheck the trigger and Kinematic properties and use OnCollisionEnter

    Edit: Oh sorry. I missunderstood your problem...
     
    Last edited: Oct 25, 2019
  5. QuarterMillion

    QuarterMillion

    Joined:
    Jul 18, 2020
    Posts:
    10
    Judging by your Rigidbody window you're not using any Constraints. You can either enter them manually in the Rigidbody's Editor window or...

    Code (CSharp):
    1. //A Rigidbody's Constraints must all be coded at once. Use '|' to add additional constraints
    2.  
    3. rigidbody = GetComponent<Rigidbody>();
    4.  
    5. rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
    6.  
    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.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    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.