- Home /
OnTriggerEnter doesnt see enemy
I have a very simple script that prints a message when a gameobject with a certain tag enters a triggercollider. And the thing is that when the enemy enters nothing happens but when the player walks in it works just fine. Heres the script:
void OnTriggerEnter (Collider other) {
if (other.gameObject.tag == "Enemy") {
print("Enemy");
}
if (other.gameObject.tag == "Player") {
print("Player");
}
}
The enemy is using the nav mesh agent with some simple code to make it follow the player. Heres that code:
private NavMeshAgent agent;
public Vector3 playerPos;
public GameObject player;
void Start() {
agent = GetComponent<NavMeshAgent>();
}
void Update() {
playerPos = player.transform.position;
agent.SetDestination(playerPos);
}
First thing I'd do to troubleshoot is to make sure that OnTriggerEnter is or isn't being called in the first place. $$anonymous$$aybe you're missing a component, or a component is present but configured incorrectly.
Answer by aman_jha · Aug 07, 2014 at 12:07 AM
Does the enemy have a rigid body on it? If the collider that checks for collisions doesn't have a rigid body, and the player does, it will register the player, but if the enemy doesn't have a rigid body, they dont recognize the collision.
Your answer
Follow this Question
Related Questions
How do I ignore trigger objects for collision? 0 Answers
OnTriggerEnterNotWorking 2 Answers
Play animation OnTriggerEnter (C#) 1 Answer
Nav Mesh Agent para perseguir a un clon 1 Answer
Collision problem in C# 4 Answers