- Home /
Vision cone with obstacles?
Hello !, I made a script of a collider trigger because it was my only alternative, it works, when the player enters the cone trigger (mesh) the enemy is disturbed, but you can see me through obstacles like walls, someone knows something?
using System.Collections;
public class VisionCone : MonoBehaviour {
public GameObject EnemyGameObject;
public GameObject Player;
void Start ()
{
}
void OnTriggerEnter (Collider other)
{
if (other.tag == "Player") {
EnemyGameObject.gameObject.GetComponent<Enemy>().Distancia = EnemyGameObject.gameObject.GetComponent<Enemy>().DetectedDistance;
EnemyGameObject.gameObject.GetComponent<Enemy>().LastDistance = EnemyGameObject.gameObject.GetComponent<Enemy>().DetectedLastDistance;
}
}
}
Answer by badadam · Jan 14, 2019 at 07:56 PM
To detect entering the player, add new object with capsule collider at cone inlet and resize to cover cone inlet. Add your script which has OnTriggerEnter method to this object. Not to pass through from cone's walls add mesh collider to your cone and check Convex checkbox of mesh collider.
Yes! I do this from my enemy vision range, because the raycast is not how to reproduce it in a script, since it is quite complex the only method I saw in a tutorial, thanks anyway!
Your answer
Follow this Question
Related Questions
Can i use pathfinding AI to make enemies avoid each other ? 1 Answer
Kill character on impact 1 Answer
Why do the AI get caught on trees? 0 Answers
NavMeshAgent does not follow player 0 Answers