- Home /
How do I use Mecanim on an NPC?
I am making an NPC, and of course it needs walking animations. I have all the animations I need ready. I am using RAIN(Indie) for the AI, and when he follows me, his walking animation does not play. I have set it up with mecanim, and the speed for it to start is 1, and he is moving towards me at speed 5. Firstly, how do I fix this, and secondly, is there a tutorial on using mecanim with an NPC?
Someone/somewhere is setting 'speed' at 5. If you manually set the speed to 1, would the NPC move?
I mean the npc should start the walking animation if the speed is 1 or greater. I tried setting it to 1, and then 5 to see if it would do anything. No good.
It's the RAIN agent that is setting the speed (and acceleration) to 5. I told it too, as stated above.
So the problem is on your NPC controller. Is it possible that you have a conflict in your transitions?
$$anonymous$$g. If (speed > 1) -> $$anonymous$$ove and If (speed > 1)-> Idle
Nope, no conflict there. The transition back to idle checks to see if the speed is less than 0.1, and the transition to walking checks to see if the speed is more than 1.
Answer by tanoshimi · Sep 18, 2013 at 08:33 PM
Using Mecanim for an NPC is no different from using Mecanim for a player character... it's a FSM - you set parameter values through script, and it processes transitions between animation states accordingly.
While your game is running, load up the animator Window (Window -> Animator), and drag it to one side so you can see it at the same time as your game window. Then, in your hierarchy pane, select the NPC object that has the animator control attached to it. The animator window will then show the states for this character in real-time, and the parameters window at the bottom left will show the values the mecanim animator is receiving from your code. The little blue line shows you the animation state that is currently playing. You should be able to see quite clearly what animation state your NPC is in, and why whatever transition you were expecting to occur is not firing
It took you 22 hours to comment on my answer, and now you're bumping it because someone didn't reply to your comment within 47 $$anonymous$$utes...? I find that pretty rude.
Yes, you set parameters through scripts, as is explained clearly, with an example, in the mecanim documentation. I suggest you read it: http://docs.unity3d.com/Documentation/$$anonymous$$anual/AnimationParameters.html
Sorry, I didn't mean to be rude, I can only be on my computer for a limited amount of time due to homework, and I just got impatient.
Where do I put the script? Do I put it in the character I am trying to control?
Yes, that particular script you put on the gameobject that has the Animator controller attached to it (because, in the Start() function, it references it using GetComponent();).
You should also seriously watch http://video.unity3d.com/video/7362044/unity-40-mecanim-animation-tutorial and download the associated project file, which illustrates a complete mecanim system.
Answer by lancer · Sep 20, 2013 at 06:23 PM
I got Mecanim running with RAIN in like 5 minutes. Personally I don't think you have done enough searches. If you look up the RAIN YouTube channel it has a tutorial for how to do this.
I have worked out what to do now. Thanks to everyone who helped!