- Home /
How do I make my monster chase me?
Hi I want to know how to do the scripting for a slender type game more specifically I am trying to have my monster randomly walk around the map without passing through walls and once you come into a certain distance from it while looking at it the monster will begin to chase you and also i need a way that you can outrun it by getting a certain distance away at which time it will resume randomly walking around the map. I have a simple follow script here:
var target : Transform; var moveSpeed = 3; var rotationSpeed = 3; var myTransform : Transform;
function Awake(){ myTransform = transform; }
function Start(){ target = GameObject.FindWithTag("Player").transform; }
function Update () { myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); myTransform.position += myTransform.forward moveSpeed Time.deltaTime; }
I tested it and it works but I want it to also walk around the map instead of being in a fixed position then once it sees me it chases me. any help is appreciated. Thanks in advance.
You only need 1 boolean variable more to control that, in example:
if(seeplayer)
//chase player
else
//go around
Actually you need some ways to handle the "seeplayer" boolean, maybe put a trigger sphere collider to the ghost, if the player collide with the trigger, the boolean will set to true; or calculate the distance between player and ghost, if it smaller than a value,say 50, the boolean will set to true;...
Answer by danilonishimura · Jul 31, 2013 at 09:34 PM
kyogretcg,
It seems to me that you're looking for a fast solution to your problem, and as far as I can tell you, there is no such thing as "SimpleSlenderScript".
You may consider breaking the whole problem in parts and try to do them one by one. Make the enemy walk around the way you think it should move, then make it look around, then make it chase you when he finds you. The implementation depends from project to project. This probably will help you to get started: http://docs.unity3d.com/Documentation/Manual/CreatingGameplay.html
Good luck ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613111308im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How could I make the AI follow me after chase = true?we 1 Answer
Item drop on monster kill 1 Answer
Enemy AI Problem 0 Answers
how to: continue invoking when the first object is destroyed 2 Answers
Enemy's NavMesh not working 2 Answers