- Home /
Question by
NeoBossGaming · Feb 28 at 11:19 AM ·
collision detectionenemy ai
My enemy collision is not working
The code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;
public class EnemyPathfinding : MonoBehaviour {
public Transform target;
private bool TouchingPlayer;
private bool TargetLocation;
public bool IsTouchingPlayer;
public Transform transform;
NavMeshAgent agent;
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "Douglas")
{
IsTouchingPlayer = true;
TargetLocation = agent.SetDestination(transform.position); ;
}
}
private void Update()
{
if (IsTouchingPlayer)
{
TargetLocation = agent.SetDestination(target.position);
}
}
}
Comment
Answer by harisriazgondal · Feb 28 at 02:03 PM
may be u have't added the colliion collider on your object and set to on triger
I already did it and it still doesn't work when I turn it on the collision doesn't work entirely I can fade trough him
After debuging I noticed that the collision is working with on trigger but it instantly says the collision ended after a milisecond. I haven't even move a singgle bit
Answer by Htss_samy · Mar 01 at 11:33 AM
Add regitbody for detect collition . you can check with
private void OnTriggerEnter(Collider other) { }