How to set a start_walking animation using blentree

Hi,

First of all, sorry if something sounds stupid in my question.
My question is about locomotion system. Do you know how to play a “start walking” animation one time just before “walking” loop animation plays ? Using blendtree ?

Here is the C# locomotion script I’m using:

using UnityEngine;
using System.Collections;

[DisallowMultipleComponent]
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(CapsuleCollider))]
public class Movement : MonoBehaviour {
	Animator anim;
	 	
	bool isWalking = false; 	
	
	void Awake()
	{
		anim = GetComponent<Animator> ();
	}
	
	
	
	void Update ()
	{
		//turning
		//jumping
		
		Walking();
		Turning();
		Move();
	}
	 
	
	
	
	
	
	void Turning()
	{
		anim.SetFloat("Turn", Input.GetAxis("Horizontal"));
	}
	
	
	
	void Walking()
	{
		if (Input.GetKeyDown (KeyCode.LeftShift)) {	
			isWalking = !isWalking;
			anim.SetBool ("Walk", isWalking);
		}
	}

	
	void Move()
	{
		if (anim.GetBool ("Walk")) 
		{
			anim.SetFloat("MoveZ", Mathf.Clamp(Input.GetAxis("MoveZ"), -0.25f,.25f));
			anim.SetFloat("MoveX", Mathf.Clamp(Input.GetAxis("MoveX"), -0.25f,.25f));
		}
		else
		{
			anim.SetFloat("MoveZ", Input.GetAxis("MoveZ"));
			anim.SetFloat("MoveX", Input.GetAxis("MoveX"));
		}
	}
}

A picture of my animator window, testing simple “logic” without blendtree system:

  • http://image.noelshack.com/fichiers/2016/21/1463994063-animator.png
    

And a gif of what I would like to realise with the character using blendtree system (if possible…) :

  • http://im2.ezgif.com/tmp/ezgif-1036784770.gif
    

Do I need a more complex script to do that ? Do I need to combine blentree system with other base layer functions ?

Anyway, hope you can help me out, thanks for reading. And of course, have a nice day.

I see you have a 2D directional blend tree already, which is exactly what you want in this situation.

The gif link gave me a 404, so I will try to offer the best solution I can without seeing it exactly.

Here, you are trying to force Mechanim to shift through multiple nodes, which is not efficient. Instead, you should condense it down into one blend tree. If you want the transition from idle to motion to be smooth, use a set up like the following:

By doing this, you make it easy to transition between the states, and your character will have to go through the walking phase for a short time before reaching full run. This is hopefully the effect you were trying to achieve (Make sure you are using Input.GetAxis instead of Input.GetAxisRaw when checking for controller input, or it won’t transition as smoothly [it wont seem to transition at all if one is using a keyboard]) .
This also adds an extra element of control, as the player can also controll how fast the character is running based on how far the joystick is tilted in a specific direction (provided root motion is being used, of course).

I hope this answered your question, and if you have any others I’d be glad to answer them.

Hi Otaku,

Thanks for your answer.
Sorry for the gif, here is a video of what I want to do :

https://youtu.be/l7GEN6k_JP8

In real life, we need to dash forward in order to engage a natural walking cylce.
In game engine, start_walking animation allows us to make the illusion of gathering speed.
We could name it as a “transition animation” instead of a “cycle animation” like walking/ runing/ sprinting/ etc.

In the video there are two animations :

  • 1st - start_walking_forward
  • 2nd - walking_forward

Actually, start_walking_forward is a really short animation that introduces walking_forward animation cycle which, in my case, is a loop.

But the start_walking isn’t a loop, it actually had to play one time only before walking_forward animation plays. Sadly, when I do what you say, the star_walking_forward animation doesn’t play well :slight_smile:

In your example, idle is actually a loop, walking is a loop, running is a loop. In my case, start_walking_forward is none loop animation beetween two loop animations so :

from idle (loop) to start_walking_forward (none loop) to walking_forward (loop)

Hope you can know what I want to do, thanks again for your support :wink: