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”).transfo­rm;

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.


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:

Good luck :wink: