- Home /
Help with Enemy AI
Hey Guys, i need some help on making my enemy follow me a little more advanced. Right now all i have is:
var moveSpeed = 5;
var target : Transform;
function Update ()
{
transform.LookAt(target);
transform.Translate(Vector3.forward * moveSpeed);
transform.rotation.x = 0;
transform.rotation.z = 0;
transform.position.y = 0.5;
}
All my enemy does is walk right to me, but what i would like to know is how i can get him to walk around walls to get to me instead of trying to walk right through them. Thanks!
Answer by whydoidoit · Mar 26, 2013 at 04:40 PM
Right well your first bet would be to do simple feeler based wall avoidance.
Cast a ray in the direction of the player and if that hits something, start casting left and right until one ray misses anything (within a range of a few metres). Move in that direction and keep casting the rays at the player and choosing the first one that misses. Your enemy will walk "dumbly" around objects to find you, but will still get caught in areas that are dead ends.
To avoid the dead-ends scenario you need a path finder, A*, NavMeshAgent whatever.
Upvoted. Further information :
.... a bit of advertising for both of us ;)
Your answer
Follow this Question
Related Questions
Enemy following Player in range 2 Answers
Enemy not rotating when inside range 1 Answer
Enemy following the target with ITween 2 Answers
Enemy AI Problem: Dancing? 1 Answer