Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Using The Animator Component in Unity3D

Using The Animator Component in Unity3D

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Using The Animator Component in Unity3D on Tue Apr 14, 2015 11:02 pm


Welcome! You may have never heard of the Animator component in Unity3D, here I am to talk to you about how simple it is to setup an animated character in Unity3D within ~20 minutes with good focus and better concentration on your animation poses, cycles, etc.
Let's begin.
What animates the animations?
Well, to start, the Unity engine will require a script to change variables and booleans around so that it knows when to play a certain triggered ammount of animations, using Blend Trees or Animation States. (Script will be provided)

1) Create a JavaScript file and named it whatever you'd like:
"AnimatorControlScript" is what I named mine

2) In this script we use the GetComponent function, this allows us to use the library of variable types in the Animator component EX: anim = GetComponent("Animator");

3) Use this script (for now I'll just teach you how to animate, later we will get to the nitty gritty of how this script actually works!
private var anim : Animator;
function Start () {
anim = GetComponent("Animator");

function Update () {
if(Input.GetKeyDown(KeyCode.W)) {
if(Input.GetKeyUp(KeyCode.W)) {
if(Input.GetKeyDown(KeyCode.LeftShift)) {
   anim.SetBool("slide", true);
if(Input.GetKeyUp(KeyCode.LeftShift)) {
   anim.SetBool("slide", false);
if(Input.GetKeyDown(KeyCode.A)) {
anim.SetFloat("running", 5);
if(Input.GetKeyDown(KeyCode.D)) {
   anim.SetFloat("running", 2);
if(Input.GetKeyUp(KeyCode.A)) {
   anim.SetFloat("running", 3);
if(Input.GetKeyUp(KeyCode.D)) {
   anim.SetFloat("running", 3);


4) now that you have that done add it to your character model

5) Add a animator component if you have not already

6) Set Update Mode to "Animate Physics", and Check off the "Apply Root Motion" boolean

7) Right click in your explorer and choose "Animator Controller"

Cool Use "ALT" and left click to move around

9) Drag in the first animation that you want for the Idle animation

10) Drag the next in for the Run Forward Animation

11) Make a transition by right clicking the your idle state and clicking on your run animation

12) Make the same process on your run animation

13) click on the arrow going from your idle animation to your run animation

14) where it says "Parameters" click the plus sign and add a new Float

15) name it "walking" and set it's value to 0.2

16) Now go back to the arrow going from your idle to the running anim and select the paramter to walking. Now that you have that completed...make sure you have the Foot IK enabled in both animations (Just click on the Rectangle)
17) You should notice once you play the game once you press W your character walks...if not, set your character to a humanoid character or to whatever your animation avatars might contain

18) Blend Trees, create a new parameter called "running" and set it's value to 3.0

19) Next Right click your idle animation and create a new blend tree from state

20) Next click on the box and add a new motion field with the plus icon

21) Add the turn right animation for your character in the top field

22) add the walk forward animation for your character in the middle field

23) add the turn right animation again in your 3rd field and check off the mirroring boolean on the right

24) Test: Use the animations: "w", "A" "D"

25) Have any questions? PM me or post a comment below for others to hear your voice

Thanks, hope you enjoyed, you trooper! You read alot, give yourself a pat on the back and keep developing!
Thank you!


View user profile

2 Re: Using The Animator Component in Unity3D on Sat Aug 15, 2015 2:13 pm


Member [Lv. 0]
Member [Lv. 0]
thanks for this script now i have animated player thank you so much Smile Smile

View user profile

3 Re: Using The Animator Component in Unity3D on Sat Aug 29, 2015 6:48 pm


Jeevan12 wrote:thanks for this script now i have animated player thank you so much Smile Smile
Yeah sure thing Smile

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum