Trigger Dialogue on OnTriggerEnter

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace RPG.Dialogue
public class AIConversant : MonoBehaviour
[SerializeField] Dialogue dialogue = null;
   void OnTriggerEnter(Collider other) 
    if(other.gameObject.tag == "Player")




Attached the script to my AI and select the dialogue but nothing happens when I enter the trigger area and press “E”. Do I also need to modify my PlayerConversant.cs?

you could set some console logs to see if the ontriggerenter event is even happening and is the collider set as trigger in inspector

I just check with Debug.Log and it is not even triggering. The collider is set as trigger yes. Any ideas? The player and the playermesh are set with tags “Player”. The yellow cube is the NPC.

Does this have anything to do with the fact that im using a playercontroller and not a regular Rigidbody for the movement?

This will not work.

OnTriggerEnter fires in the frame that the player entered the trigger. Once. In that frame. GetKeyDown returns true in the frame that the player pressed the key. Once. In that frame. The only way this will work is if the player pressed the key in exactly the same frame as the character entered the trigger area, and the odds of that happening are pretty small (not impossible).

Try using OnTriggerStay instead. See the documentation here

1 Like

I think one of the objects needs to have a Rigidbody to register a collision. The colliders just set the boundaries for collisions. The Rigidbody is what detects the collision has occurred.

Thanks to both I’ll try when I get home.

thanks fixed after OnTriggerStay!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms