- Home /
How to Check for Enemie in Front? Raycast is not Enough!
Hello Community,
actually im back to working a bit with Enemies and AI.
So the Enemie should detect the Player in Front of him. As far so good easy to Archive with Raycast but this is not very precise.
The Problem is
When i Raycast i have to Stand Excactly in Front of the Enemie that he is able to Detect me.
But rofl... no Eyes in this World only look in 0 Degree Angle forward.
So if i stay next to the Enemie and im not in the Direct Line of the Raycast he cannot see me even im Next to him.
Now you say Use SphereCast. But did you see a Human have Eyes in his Back?
Okay. I want to Archive that he is looking forward in a Corner and Detect whats in Front of him. Thats what i actually try to Archive but i have no Clue how.
Maybe someone can give me a Hint or Example how to Archive this. This would be really awesome.
Thanks in Advance
Answer by poisoned_banana · Apr 22, 2018 at 05:01 PM
Use Vector3.Angle in combination with SphereCast
Answer by Karsten · Apr 22, 2018 at 07:48 PM
You didnt really search i think. Look at the Vector3.Dot and think about it.
Actually im searching alot in the API, Forum and Answers. But its a bit hard for me because my English isn't the best. So it's sometimes hard for me to understand what they exactly mean in the API.
I try to improve my English but it will take time :p
I found the Vector3.Dot already but its actually not clear for me, but im working already around and the Hints are actually great. $$anonymous$$y Enemies detecting already in a front corner but i think i got a problem in my State $$anonymous$$achine because its always switching from Chasing to Scanning.
Your answer
Follow this Question
Related Questions
How to check if an empty GameObject is inside an object? 2 Answers
2d raycast enemy detection problem. 0 Answers
Raycast causes all enemies to attack 1 Answer
2d Raycast problem from enemy to player C# 1 Answer
Multiple Cars not working 1 Answer