- Home /
how to put like a camera on the enemy so he can see you only in a specific angle?
In my game the enemy has a script that check the position 25 far away from the enemy making a circle around him. I make and point 12 m away from the enemy. That works but not to well so I want to know a way to put the enemy like having a camera so that way he can detect some one in that angle then only in some distance the enemy can see you and if its posible put a var certainty that the enemy when you are closer he has more certainty and when you are far he has lower certainty that you are there.
Please if someone can help me I would greatly appreciate it. :)
Answer by Adam Rademacher · Oct 22, 2010 at 03:44 AM
One would typically use a Vector3.Dot solution for this. Dot products compare two vectors and determine the directions they are facing in. Subtract the player position from the enemy position to get the facing vector (this is the vector between the enemy and the player), then take a Dot product to determine how close the enemy is to matching that direction.
The script reference on Vector3.Dot is pretty good and has an example that fits your needs.
but if I want to have a specif angle to see what I have to do and also what I have to do with the variable certainty
You'll have to play with numbers a little bit, I suspect. If the Dot product = 1, the enemy is facing directly at the player...if the dot product is 0, the enemy is perpendicular, and if it is -1 they are facing away from the player. So a dot product of .5 would be about a 90 degree "field of view" if you want to think of it (half way to a full perpendicular on each side).
The dot product is the cosin of the angle between them. So if you want 25 degrees, cos(25) is about 0.9. So check Dot(enemy.transform.forward, player-enemy) > 0.9 (really is a greater than, since 1 is facing and lower is more turned away.)
Your answer
Follow this Question
Related Questions
Limiting a distance variable 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Simple enemy kill count 1 Answer
Adding y position? 4 Answers