- Home /
Enemy shouldn't see you through walls
Hi folks,
I am using Javascript and this is my script I have for now attached to my enemy.
var Target : Transform;
function Start ()
{
Target = GameObject.FindGameObjectWithTag("Player").transform;
}
function Update ()
{
var distance : float = Vector3.Distance(Target.position, transform.position);
var targetDir = Target.position - transform.position;
var forward = transform.forward;
var angle = Vector3.Angle(targetDir, forward);
if (angle < 45.0)
{
Debug.Log("Can see player");
}
}
Well the problem is, the enemy can see through walls what is not supposed to be. How can I make the enemy can't see you through walls?
Someone who can help me please? I am struggling now for days..
Thanks in advance
Comment
Best Answer
Answer by siaran · Apr 17, 2015 at 11:52 PM
Do a raycast from your enemy towards the player. If the ray hits the player, the enemy can see him. If not, the enemy cannot.
Your answer
Follow this Question
Related Questions
Raycast stealth enemy? 1 Answer
Increase Field of vision of Enemy over time 1 Answer
How can you make an enemy follow you only when look away or blink? 1 Answer
Enemy VISION range? Help! 0 Answers
Obstacle avoidance not working 0 Answers