how to make enemy chase player using the view of eye ?
i am try to follow CCTV camera oficial tutorial unity3d . but it’s not work when i try that …
do you have any solution ?
make enemy chase player using the view of eye ?
sorry my bad english …
Couple of ways of doing this, depending on how responsive you want the enemies to be and your Unity knowledge:
- You could create a primitive cube, child it to the enemy gameObject, and position/scale/rotate it to the ‘range’ you want the enemy’s view to be. Then, disable the cube’s renderer to make it ‘invisible’ and toggle the collider to be a Trigger. GameObjects can now pass in and out of the cube’s collider and you can detect their ‘collisions’ with OnTriggerEnter and OnTriggerExit. You can then tell the enemy to chase the player or not dependent if the player is inside or outside the enemy’s (cube) view.
- Instead of using a ube, you could create a Cone in a 3D modelling program and generate it’s colliders when you import it into Unity. Then just setup the Cone like you would with the cube in the previous example.
- You could use a Raycast, and send one from the enemy’s eyes/head/body straight forward to detect if the player is in a direct line of sight. This wouldn’t be a ‘range’ and would be less ‘accurate’ when playing the game but it is another method.