- Home /
Animations - Can you cut them?
I am currently working on a 2D game project and I am running into a few small issues with animation. I am trying to use the Animator to create basic states for the character, states such as Idle, Walking, Running and Jumping. I have managed to do this however I would like to know if it is possible to implement a system what can cut an animation halfway, if you look at this project : Project you will notice how if you tap the arrow keys, the character takes an entire step to the side. I would like to know, is it possible to prevent this, from my experimentation I have found that state conditions are only checked upon starting the animation, while playing it does not check the state conditions to see whether or not it can keep playing.
I am using this script to manage the states :
public class AnimManager : MonoBehaviour
{
Animator anim;
public float fakeinput;
public float threshold;
public bool moving;
public bool left;
public int movingHash = Animator.StringToHash("Moving");
public int leftHash = Animator.StringToHash("Left");
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", move);
//move = fakeinput; // FAKE INPUT FOR EASE OF ANIMATION TESTING
if (move <= 0.0f + threshold && move >= 0.0f - threshold)
{
moving = false;
}
else
{
moving = true;
}
anim.SetBool("Moving", moving);
anim.SetBool("Left", left);
}
}
Is it possible for me to cancel or cut / blend back to idle if the animation is playing and the " moving " boolean is marked as false?
Any help would be massively appreciated.
Answer by hippysniper · May 08, 2014 at 11:56 PM
use animation.blend http://docs.unity3d.com/Documentation/ScriptReference/Animation.Blend.html
if(!moving){
animation.Blend("idle",1,0.1)
}
I am using the "Animator" class though, I cannot use that function. Is there an alternative on the Animator class which I am not seeing?
Answer by Sparta5_6 · May 08, 2014 at 11:53 PM
Why don't you just delete the animation keys?
I do not have much experience with the Animator system so, could please you explain more what you mean?