|
I have a script that checks whether the player is in line of sight of an enemy using raycasting, however I always want to only return true if the player is in front of the enemy. How would I do that.
(comments are locked)
|
|
See this answer, except use Z instead of X. That's even easier... ;)
Apr 26 '10 at 04:43 PM
StephanK
That resource is no longer available. Would you mind directing me to an updated location?
Aug 01 '12 at 01:58 AM
DESTRUKTORR
Updated link.
Aug 01 '12 at 02:19 AM
Eric5h5
(comments are locked)
|
|
Calculate the angel between your forward vector and the enemy position. If absolute value is bigger than a certain threshold (eg. 90 degrees) it's behind you. To do that there a some very convenient functions:
Not tested but should work. I totally wish there was a Vector3.Angel function. :)
Apr 26 '10 at 11:13 PM
Eric5h5
Well, sometimes even wishes come true... http://unity3d.com/support/documentation/ScriptReference/Vector3.Angle.html
Apr 27 '10 at 05:56 AM
StephanK
@spree: a month late, but: no, that did not make my wish come true. Read again, more carefully. ;)
May 30 '10 at 04:00 AM
Eric5h5
Lol. I see it now... ;)
May 31 '10 at 02:27 PM
StephanK
(comments are locked)
|
|
I know it's been a month since any comments were left on this, but posting as the link in the answer no longer works. So regarding spree 1's code above, for complete 360 degree detection, I think it should be;
(comments are locked)
|
