Im trying to get an enemy to detect where the player is but at the same time restricting his vision to a cone from his eyes and forward.
The cone is an invisible object which should detect collisions using OnCollisionEnter.
When collision is detected, it should use a Raycast to see if the object is in sight (and not behind a wall that the cone is penetrating).
This is my code so far, and after messing with it for an hour or two now I cant figure out why the detection isnt made.
The script is attached to the cone-object, which is a child of the enemy-object. For testing Ive used a unity-created cylinder instead of a cone, and unchecked Mesh Renderer. It will still prohibit me from moving trough it, though, so I havent solved that issue yet. How?
The player-objects name is "FPS".
You should use a trigger for the cone, and OnTriggerStay() for the raycast code. If the player is a CharacterController, it will also need a kinematic rigidbody attached with some kind of primitive collider in order to interact with the trigger (see the docs about colliders and interaction).
answered Jan 21 '10 at 05:37 AM