Enemy AI makes enemies walk up walls? **SOLVED**

I have enemies with ai’s that follow you around but the enemy can basically walk up any slope no matter how steep. How can I stop it from doing this? Also sometimes whenever they hit a wall or something they go awol and just start running in random directions. by the way i got this script online and have no idea what im doing with it (sorry for my noobishness)

#pragma strict

var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
 
function Start () 
{
 
}
 
function Update () 
{
    transform.LookAt(Player);
 
    if(Vector3.Distance(transform.position,Player.position) >= MinDist){
 
         transform.position += transform.forward*MoveSpeed*Time.deltaTime;
 
 
 
         if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
             {
                //call function here
   } 
 
   }
}

1 Answer

1

Well, I’ll explain to you step by step what it’s doing.
Then we can try to find the answer shall we :).

First Step… The enemy is always, ALWAYS looking at you.

if your distance is GREATER than your minimum distance than they are going to charge after you.

If your distance is LESS than your Max Distance - Do nothing.

That’s exactly what you have going on here.
So lets try to diagnose this shall we?

They obviously charge after you, so that means you should look at NavMesh.

it’s simple, don’t worry!

okay thanks :) for that. I was just daunted because I have 0 experience with using code to move objects.

Don't worry bro, we've all been there, I've been using Unity for almost a year now, and I'm still learning basics lol.

So what is NavMesh?

actually i just googled it and set it up. Now it works great :D

Remember to mark the answer as accepted rather than just adding solved to the title ![alt text][1] [1]: http://answers.unity3d.com/storage/attachments/27269-howtotickananswer.png