- Home /
AI Patrol via Script
This might be a long post because my problem is (to me) quite complicated so I will try and make it detailed for anyone able to help because I have been trying for a solid four days and no results.
I have gone through all of the Unity tutorials (multiple times) and feel like I have a good handle on AI in general but they aren't very helpful when it comes to modifying their examples (or maybe it's just me)
I have done a lot of stuff with animating a character controlled by the player (in 3rd person) but now want to move in to more complicated AI behaviours.
So I have a basic floor (set to static) and a baked navigation mesh for the AI.
I also have 4 waypoints (represented by cubes) to indicate the AI patrol (waypoint 1 > waypoint 2 etc)
Then finally are the AI animations that will be used during patrol, chasing the player, attacking and death. (I can't attach any more pictures)
Normally (in my experience with player animations) I would setup an animation controller and attach it to the player in order to cycle through the animations with parameters.
For example, the transition from idle to walk might take a boolean of walking (true/false) and play the walking animation when the walking boolean is set to true.
Is this the preferable way to handle AI animations? Attatch an animation controller to the AI and a boolean like isIdle... then inside an attached script create an isIdle() method which is set to "true" on Awake()....
or do I attach all of the animations using the "animation" component and then cycle through animations via script (without the use of an animation controller)? so instead of isIdle() it would be something like
void Awake() {
animation.Play("Idle_01");
}
The reason I ask this is because I tried setting up an animation controller where the default state is "Idle" yet the animation does not play. However, when attaching the idle animation as an animation component and selecting play on awake... the animation works fine. This leads me to believe I need a different approach to AI navigation/animation than I do with player animation.
The problem appears to be the fact that the AI rig is marked as "legacy" whereas previous models I worked with were "humanoid". Not sure how to resolve that issue though.
Answer by zviaz · May 04, 2015 at 07:29 PM
Found a solution (just incase anyone else has the same problem)
Both the AI model and the animations were set to legacy. I had to convert the model and animations to "humanoid" thus generating a new mask for the AI. This mask is then attatched to the AI via the animator controller and works.
Your answer

Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
Unity animator state finished, motion not 1 Answer
How to make 2D Sprite Animation frames spread over the duration of the motion time 0 Answers
Why have some of my prefabs and animations files gone blank?? 1 Answer
Change animations associated with an animator from C#? 0 Answers