Search Unity

Why the OnTriggerEnter never detecting ?

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

  1. DubiDuboni

    DubiDuboni

    Joined:
    Feb 5, 2019
    Posts:
    131
    On the npc I have a Box Collider Is Trigger is set to false unchecked.
    I also have on the npc a Rigidbody both use gravity and is kinematic checked true.
    And on the npc also attached this script :

    The idea is when the npc hit a door that also have a box collider the npc will stop walking.
    I have a parameter in the Animator called Walking Speed set to 1.0 and I want to set it to 0 when colliding with the door but it's never reaching to the OnTriggerEnter in the code I use a break point.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class DetectColliders : MonoBehaviour
    7. {
    8.     private Animator animator;
    9.  
    10.     private void Start()
    11.     {
    12.         animator = GetComponent<Animator>();
    13.     }
    14.  
    15.     void OnTriggerEnter(Collider collider)
    16.     {
    17.         animator.SetFloat("Walking Speed", 0);
    18.     }
    19. }
    20.  
     
  2. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
    Shouldn't npc have Is Trigger checked ?
     
    DubiDuboni likes this.
  3. DubiDuboni

    DubiDuboni

    Joined:
    Feb 5, 2019
    Posts:
    131
    Right. It's working now, Thanks.