I'm using Animator to more easily control the state of a player sprite. Player sprite has only one frame for different animations (single image per different state), however - animator shows that it plays each frame 17ms.
So when player jumps I set animator parameter "InAir" to true, it should change sprite image instantly to InAir state, but for single frame previous state is visible (I believe it's because it takes 17ms for animator to transition) and in game there is noticeable flicker after jump.
How should I implement instant transition or is it possible to change the animation play time?
I had the same issue recently in Unity 5.3. I fixed it by clearing any Exit Time values for the transition. For some reason when the transition was created it was given some Exit Time default values which added extra time to the animation.
It can be seen by clicking on the transition and viewing the Inspector window.
My transition happened instantly when I disabled the Has Exit Time checkbox, and cleared the values under Settings.
Related
When in the game editor the game runs as intended and we can pick-up each object selected and move it from point A to point B. When building the game the game starts as intended but after a few moments, we noticed that the collider triggers for the object we want to be picked up are moving upwards indefinitely. There is an animation attached to the floor which will move the player and objects up when activated but the player has to complete a task for the animation to start.
We noticed this because we have an indicator which shows when the RayCast hovers over the collider to pick up the object, and it moves upwards after start.
This issue occurs on every object intended to be picked up in the scene that the player is currently in.
In editor the colliders don't move and the items can be picked up as intended but the issue came about ONLY when trying to build the game.
Tried:
Adding kinematics
Removing gravity
Removing every animation attached in the scene
Changing each part of the objects RigidBody
Changing the Awake() on pick-up script
Running in developer mode
Is this an issue where you're not accounting for the framerate? In other words, do you need to incorporate Time.deltaTime in your Update loop somewhere? This feels like that because I'm thinking the frame rates could differ drastically between the unoptimized editor environment, and a full build.
For example, if I'm moving an object 10 units each frame like this:
Update()
{
// Move to the right
transform.Position.x += 10;
}
Then that is frame rate dependent. On a device with a low framerate, the object will move slower than on a device with a high frame rate. On a 30 average fps device the object will move 300 units per second. On a 120 fps device the object will move 1,200 units!
That code should look something like this to account for frame rate changes:
Update()
{
// Move to the right
transform.Position.x += 10 * Time.deltaTime;
}
You may need to adjust the "10" value because now it's related to how fast the object is moving per second. Each Update will move the object a proportional amount of time for that frame.
(The above implementation probably isn't perfect, and introducing things like networking/multiplayer could require additional changes.)
See the docs for more information about Time.deltaTime
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.
I'm trying to make a cube in unity move using an animation I made in unity. When I press "W" the cube should animate to another position, but when the animation is finished it goes back to where the animation started. Also when I do the animation the animation starts at the position where the animation was created. I tried fixing this with applying root animation to my cube and checking the "Generating root motion curves at runtime" option in my animation inspector. But when I do that the cube won't move. Can I get some help with this issue.
This behavior is quite normal, once the animation stops. You have a couple of options.
If the animation is only about translation and rotation, then do it the straightforward way (without the animation) and by manipulating position and rotation
Create another animation that starts in the last frame of your moving animation and loop it (you have finite state machines in Unity for animations)
Cache the current position and rotation of your object, detect the
end of the animation and set the position and rotation to the last
cached values.
I have player and his climb animation, so i want climb_end animation position save to game object player. I don't want return back to player position after last animation frame. Thanks
Make sure the animation is not set to loop (uncheck looping in the animation file).
Also, make sure "Has Exit Time" in the animation controller's climb_end animation state is unchecked. This might be causing the animation state to move onto another animation after it's finished running.
I'm using unity 3d v. 5.12 and for some reason, when I'm using an animation (made with unity, *.anim), any changes to a game Object's position are not applied. Please help. I'm totaly new to unity.
Before recording your animations, you should setup the properties of the animation by adding "transform position/transform rotation" in the animation window.
Once you're done recording your animation:
1 Click "Generate motion curves" on your animation object.
[Setup your object with its animation controller]
2 Set the animation controller in your object to "apply root motion" (tickbox)
Your object will now rotate/move independently of the objects rotation/position
If your animation is animating position component then any changes to position during animation is playing will not affect gameobject it will be controlled by animation. Same case applies to imported animations as well . And not only position if any other component is controlled by animation it will not be affected by code during animation is playing i.e scale rotation etc..
Here's the rule:
Any object that has a keyframe in the currently active animation cannot move (except for by the animator), it's FROZEN.
The rule stretches:
If there is a transition arrow from the currently active animation to another, that one is considered active and no objects with keyframes in that animation are allowed to be moved outside the animator either.
Summary:
If an object cannot move because of the animator, it is involved in the currently active animation or one of the transition animations PERIOD