- Home /
How To Make An NPC Move When You Look At It
Hello all,
I've searched but can't find exactly what I'm looking for, let me be more specific. I have a hospital environment that has several turns/corners the player must walk around. I also have a man, that I want to walk around each corner before the player does. Let me clarify though.
If the turn is right, and the player is looking left, the man will not walk. Once the player sees the man, he will walk around the corner. Then when you turn the corner, he will just be walking around the next corner etc. This will happen several times. I will then just need him to walk straight after the final turn. - How do I accomplish this? - And yes, I have the model with the animations. I just don't know how to apply it.
Thank you for your time.
P.S. I'm sorry if this is a double post. I typed this all up and then it asked me to log in and I didn't see it posted :/ So I'm hoping it only posted once.
Answer by cdrandin · Jan 20, 2013 at 03:10 AM
I had an idea on using a Ray to determine when play visual looking at target. There is no such thing as Ray cone unfortunately. My next idea was having a trigger, if player is in trigger, PREPARE man to walk, but it needs one more condition, if player is in trigger AND visually looking towards this man, have the man perform the action. For this you can use http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html this might work, if the spherecast is towards the man object, then activate man to walk.
Hey,
Thanks for the quick response! This was useful info. I appreciate you taking the time to lay it out for me and link me to that page. It also sparked a few other ideas as well, so really, thank you.
Answer by Professor Snake · Jan 20, 2013 at 06:23 PM
You could use the OnBecameVisible() function along with some occlusion culling.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091227im_/https://answers.unity.com/themes/thub/images/avi.jpg)