I'm currently having a problem with Unity Animator and I haven't found a solution yet. I'm trying to animate the position of a UI object through its Anchored Position with Unity Animator. Even though I have the checkbox Apply Root Motion active, when the animation ends it returns to its original position, instead of maintaining the position that changed.
I activate the animations through Triggers in a Script, and all the Scripting logic works well. The expected behaviour would be like you can see in the gif, but moving through the connectors instead of turning back to its original cell.
I tried to make an Empty GO the parent and animate child, remake the animations, remake the animator, etc., but nothing worked so far and I don't know what to try next, and I could use some help.
Thanks for answering! I will answer anything necessary when asked!
Current State Gif:
Animator Screenshot:
I can't be sure why your apply root motion is not working as it should but you can fix this in another way.
You create 3 animations with the Anchor Position, one at the startpos, one for the transition from the first one to the end one, and the endpos.
Start animation and end animation should be looping while for the transitioning one you can uncheck the looping in the inspector of animation
In the animator set the startpos as default state and create a transition with the trigger to the moving animation. Then add a transition from this animation to the idle end position without a condition but just has exit time set of the time the last animation will play
In this way, it should all work fine and if you want to come back to the first position you can add another transition with a trigger to the start or whatever you prefer.
Related
DESCRIPTION
I am learning to use Animation Layers. I created one with a mask so only the torso and head are affected. It has an empty state so that the animation isn't played first thing automatically, which transitions to a torso hit animation when a trigger is activated. The animation is set to Additive with weight of 1 as I want the the animation to be played with all of its intensity.
The animation works beautifully and when my character is shot in the torso it seemingly winces from the pain by bending its torso down while continuing to run or do stuff.
PROBLEM
After the animation is completed, the character remains with its torso bent down and continues running/doing stuff in that position instead of simply assuming the position of whichever animation is playing in the Base layer.
WHAT I TRIED
Fiddling with all of the settings visible in the image below, including "has exit time" and "interruption source", creating a transition back to the empty state and googling. Unfortunately, this is the full extent of my knowledge.
SETTINGS
QUESTION
How can I have the character revert back to the position of whichever animation is playing in the Base layer after the hit animation is played?
You don't have any transition back from Torso hit to New State.
Try adding one with
has exit time = true
exit time = 1
Like this (might want to adjust the duration of course)
I have imported some Maximo animations, but when i use them i see that the character moves with the animation. when i walk for example i want it to be done via code and not the animation. how can i do this?
my animation rig is set to Humanoid, and also to loop when it ends.
i have tried to check if i can find it in the animation window, and if i can see the changes but no result. i think its the animation itself that changes its position. so please help me find this out or help me find another software where i can create an animation without moving the player.
i am talking about walking/running animations i need a way to not move it via the animation but via my character controller script.
Pretty sure you just need to turn off root motion.
https://docs.unity3d.com/ScriptReference/Animator-applyRootMotion.html
Just pick your avatar and uncheck "Apply root motion", or you can change it via code if you prefer.
I want an enemy to look at the player when he shoots him, I call this function from an animation event:
public void ShootPlayer
{
thisTr.LookAt(playerTr);
thisTr.rotation = Quaternion.Euler(0, thisTr.rotation.eulerAngles.y, 0);
GameObject newArrow = Instantiate(straightFlightArrow, shootPoint.position, transform.rotation);
em.canMove = true;
}
It does get called, but model`s rotation does not change. The weird thing is, if I invoke thisTr.LookAt(playerTr) in Start(), the model will rotate accordingly during the shoot animation. Also, if I rotate the model from another script the same way before the shoot animation starts it will work as well.
So for some reason trying to rotate the model specifically from the animation event does not work for me. I have tried checking constraints on and off, applied and disabled root motion, but there is no effect. I am sure that there is some obvious mistake that I make, but I just can`t figure it out.
Properties that are being animated (i.e. inhibited by the animation engine) cannot be set from code. There's a workaround for it, but it's ugly - you need to do your update in LateUpdate() (so it's after the animation engine does it's transformations) and you have to keep track of the updated value, overwriting it each and every frame (because otherwise the engine will overwrite your next frame with what it had calculated).
Other workarounds involve wrapping GameObjects in empty GameObjects, i.e. my animator animated an object's position, which I wanted to change in code as well, so my structure was:
animatedContainer
|- actualObjectAlsoAnimatedFromCode
As far as I know this also applies to properties which are inhibited at some point, but not necessarily changed during current animation (and I think this is the issue your case is facing).
I am trying to animate a warrior,
He has a special hit using the sword.
Jump, and hit..
During the animation he takes some steps to the front and after the animatiin is done.
It goes back to the idle state leaving the new position.
It annoys too much.
So what I am asking.
How to keep the new position and change the collider position to that new position?
How to keep the new position
Depends how you animate it. But essentially,
Make the animation not loop
Make it not transition to other unwanted animations.
Have the next animation begin from the endpoint of the previous one.
and change the collider position to that new position?
The collider position will follow the position of whichever object it is located on. Also if they are animated. So if your collider is on a leg and you move the leg outward, the collider will follow that same animation.
Additional information
If you don't know how to make things work from here. It would be great to show the code you are using (if any) and how you make the character animate.
If it is with an animation controller, please display the transitions and animations of it in a screenshot.
Always try to provide relevant scripts and screenshots when asking questions.
I have a game I am making where I want that the player has no animations until it hits a certain trigger. Then I want a short animation to be played, then it will stop the animation again.
To get this effect I have the above animator state machine attached to my player, and when the player collides with the trigger it plays the Halfway animation, then it goes back to the empty state. All of this seems to work fine at first but while my player is in this empty state loop thing, I cannot move it. I am using "rb.velocity = new Vector3(stuff);" to move my player, and when I disable the animator component I can move fine. I was wondering if
There is any way to enable movement while I am in this empty state,
There is some way to get rid of the entry transition entirely so I don't have to have the empty state at all, or
Pretty much anything else that would make this work :P
If you need more information let me know, I will try and help you help me as much as I can. Thanks!