|
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. :)
(comments are locked)
|
|
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
Oct 22 '10 at 08:58 PM
user-4347 (google)
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).
Oct 23 '10 at 03:42 AM
Adam Rademacher
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.)
May 10 '11 at 05:15 AM
Owen Reynolds
(comments are locked)
|
