D
D
Dred Wolf2021-04-07 13:33:16
Game development
Dred Wolf, 2021-04-07 13:33:16

How would you make enemy NPC vision for stealth mechanics?

I'm trying to figure out how to implement the following mechanics for a 3D game:
when a player is in sight of an NPC, the NPC attacks. I tried to attach a camera to the NPC and implement a script that reacts to the player's meshes entering the NPC camera's field of view, but then the NPC camera ignores any objects and sees the player through the walls. How would you do it smartly, please share)) not necessarily the code, you can give me some advice so that I know which way to dig. (mechanics for stealth horror game which)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2021-04-07
@GavriKos

No need to do it "on the forehead" as a camera. Solve this question geometrically.
If there is a small distance from the enemy to the player AND the player falls into the field of view (also a common geometric formula) AND there are no walls between the player and the enemy (here is a raycast) - then he is in the field of view.
Of course, you can do it with a pure raycast, or even on colliders.

N
namee, 2021-04-07
@namee

one more camera will render graphics and it will be very expensive in terms of resources.
Better solve it with math

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question