- Home /
Stop LookAt Function. Lock the rotation
Hi Community! I have a problem. I want my enemy to LookAt the when the player isnt looking at him:
if(renderer.isVisible)
{
Debug.Log("i can see you");
//insert Stop Lookat thingy here
}
if(!renderer.isVisible)
{
transform.LookAt(player);
Debug.Log("Can't see you");
}
so how can i stop the Lookat function?
Comment
For curiousity's sake, how did you solve it? Personally, I would have implemented a new function called LookAway for the enemy that would re-orient them to look in a different direction, but I would be interested in hearing what strategy you chose.
Answer by callenord · Aug 28, 2012 at 01:40 PM
well first i made a boolean called "looking" and made it false. then i... well here's the code:
if(looking)
{
transform.LookAt(player);
Debug.Log("he's looking at you");
}
if(renderer.isVisible)
{
Debug.Log("See you");
looking = false;
}
if(!renderer.isVisible)
{
Debug.Log("Can't see you");
looking = true;
}
thats how i did it! :)