I'm making a basic 2D character animation where the character can move left/right/up/down. I've got four "look" animations for when the character is standing still and four "walk" animations for when the character is moving. In my animator, I've got triggers isStopped and isMoving. When the character starts moving, I set isMoving and when the character stops moving, I set isStopped.
Everything's working except for a weird behavior that when I click somewhere for my character to move, he quickly enters the "look" animation for a fraction of a second before changing to the correct "walk" animation. I can verify this by looking at the Animator window in Unity to see which state is being entered.
As soon as the character begins moving, I set the isMoving trigger, and when the character reaches its destination, I set the isStopped trigger. I also have a facing integer parameter which I set to 1, 2, 3, or 4 during each update cycle.
Here is a screenshot of my animation setup.
Why is he entering the "look" animation prior to entering the "walk" animation?
I figured it out. I was setting the isStopped trigger twice. I didn't realize the trigger would stay set until it was consumed by another animation changed.
Related
I'm trying to animate a spaceship barrel roll, and for some reason when the roll animation end, the ship goes back to the starting position. Attaching a GIF to display :
https://gfycat.com/glaringgrotesqueherring
https://gifyu.com/image/tQ8I
Here is how I set up the animator, as you can see there are no properites on the idle animation:
What am I doing wrong? Thank you.
I've made an animation on an Image object in my Unity game. When the animation has finished it animates back to its original position! I'd like to stop this from happening. I've tried Googling and searching here on SO but can't see any solutions so far! My animated object has an Animation and Animator components attached to it. The Animation component has an array of 3 animations. I only want to ensure one of them does not loop back to its default/original position.....
Here is a screenshot of the animation components attached the gameobject:
I suppose in the animation sequence the last frame is the same as the first frame? This is what usually happens and restores the animation to the original position. Try removing the "loop" tick of the animation as well as check the first and last frame.
I had the same issue, and I solved it just now. You must unchecked to Root Transform Position(XZ) / Bake Into Pose, from inside your animation.
So I have a bunch of mecanim animations.
I have tried various combinations with "Root Transform Position (XZ)" (e.g. Checked, unchecked, Orginal & Center of Mass & "Apply Root Motion")
The issue is, every combination fails in some regard.
Note: My animation moves the character
Thus, I would like the GameObject to be exactly where it is after the animation completes.
However, if you uncheck "Root Transform Position (XZ)", regardless of the animator's "Apply Root Motion" being checked or not, the animation does not move the GameObject during the animation.
If you do check "Root Transform Position (XZ)", it moves the GameObject (as it should), but after the animation completes, it still exists in the original (starting) position. (Which is bad and a false illusion.)
How do you fix this? Or programmatically set the new position to where the animation ended the GameObject?
Thanks!
I have this structure of animations:https://i.stack.imgur.com/Rv0fq.png
The idle state runs in a loop until the user presses "space",then parameter named "Jump" becomes true and the transition between idle and Jump becomes active.But before it becomes active user has to wait for "idle" to finish.How can i make it so when user presses space,idle automatically stops and transits to Jump? I tried making 'animation' stop like this:
if(Input.GetKeyDown("space")){
anim.Stop();
animator.SetBool("Jump",true);
}
But it didn't work.
Ok, I warn you the jump is not that easy.
You will need to know if the player is on ground if you don't want your player to be able to jump in the air and many other things.
Anyway to your question.
To avoid exit time on animation you should uncheck the "Has exit time" value on the animator arrow between an animation and the other one.
Your current code just stop the animator but that's not what you really want... you want it to return to Idle.
The best thing you can do is:
- From "Any state" to "Jump" (you should create a blend tree between Jump and Fall)--->in the arrow uncheck "Has exit time" and set up a new Bool "JumpBool" (for example).
From "Entry" to "Idle"
From "Jump" to "Idle" when "JumpBool" is false.
In your code:
if(Input.GetKeyDown("space") && !OnGround()){
animator.SetBool("JumpBool",true);
}
(you should create your OnGround method).
else if(OnGround()){
animator.SetBool("JumpBool",false);
}
Of course this is almost pseudo-code. Like I said you should create a BlendTree for Jump and Fall where you should be able to tell if you need to play the jump animation of just the fall animation (maybe with a float depending on your corrent rigidbody .velocity.y speed).
I downloaded 2 animations from Mixamo called Idle and Walk_Forward. I created my controller with blend tree and it worked fine. But the problem is when I press W button, the character only move a short distance then back up to the orginal place where he start "Idle". Someone told me to download animation with "In place" option. So I tried then had another problem: The character just play animation but not move forward. About my component on character, I created RigidBody with Use Gravity, and the animation and character is humanoid type. How can I make those animations work ?
If you are using an animation which animates in place then you'll have to add a characterController to make you're character actually move. The animation will only make it look like you'r player is moving. Here is an example of how to move your character.
Implement import of model settings and set "Animation Type as humanoid" in the Rig tab. Then press Apply. Now your animation would not repeat.