- Home /
Wandering AI Monster
Hi, I'm making a simple hunting game with an alien theme. The story is you're on an island in an alien world, and you have to hunt to survive. I have a weird alien dog-like monster that has a walk animation. I want it to walk around randomly until it comes close to the player or vice-versa. When that happens I want it to run away until it's twice as far as when it first detects the player. I have no idea how to do this, can anyone help?
Answer by Thom Denick · Jul 24, 2010 at 09:42 PM
Hi there,
Assuming you are making a 3D Game, for the solution to this, I strongly recommend the 3rd person Platformer tutorial provided on the Unity site. It can be found here:
http://unity3d.com/support/resources/tutorials/3d-platform-game.html
If you are well-versed in scripting and the Unity engine, I would go ahead and skip to the chapter on the enemy AI (the chapter titled "Adverseries" Page 69 in my Reader). The robots behave in a manner similar to what you are describing.
If you are completely new to Unity - definitely try some of the easier tutorials, 3D Platformer assumes you are already fairly well-versed in Scripting and the Unity platform.
thanks, i'll check it out, in the mean time, anyone is welcome to continue posting answers
It was too complicated, I want it to be way more simple. I don't even want it to attack. I don't have many animations for my monster.
Answer by oz m · Jul 24, 2010 at 11:07 PM
I made it so if I go close to it, it walks away. I still want it to roam around when I'm not close and it also has a little glitch. If I'm above it on a hill or jumping while I'm close enough, it starts to go down under the terrain. Also if I'm really close to it, it sometimes starts walking in midair. Here's my code:
var person : Transform; var detected : boolean = false; function Update () {
if(Vector3.Distance(person.position,transform.position) <= 30) { detected = true; } else { detected = false; }
if(detected) { var relativePos = person.position - transform.position; relativePos = relativePos * -1; var rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
animation.CrossFade("walk");
transform.Translate(Vector3.forward * (Time.deltaTime * 2));
} else { animation.CrossFade("idle"); }
}
Can someone please help?
I think your problem might be that your manually transfor$$anonymous$$g your creature's position, forcing it beyond your collision detection. Try attaching a Character Controller and instructing the Character Controller .$$anonymous$$ove. Again, I think you'll find the bits and pieces you need in that tutorial, definitely worth the four hours or so required to go through the tutorial.
Your answer
Follow this Question
Related Questions
Enemy AI monster problem 3 Answers
how to make an enemy Ai blow up when you shoot it? 2 Answers
Monster AI patrol an idle 0 Answers
enemy shoot AI precision 1 Answer
Auto shooting script. 1 Answer