Since I have started on Unity, I follow a lot of tutorials, and it seems to be good for me
Before started :
Unity 5
I’m developping in C#
2D Project with Sprite
So, my problem is simple, I can fix it with code, but I’m trying to fix it via the Interface/Animator.
I have a unique GameObject with a simple Sprite on it.
Two animations: Idle/Run/
Both of them are “Make transaction” very simple with Speed>0 and Speed<0.
My animation are working fine on the keydown, but when I quickly pressing the “move foward” button, my character move on a few distance, but the animation of “Run” is going until it ending. So my character should make “one step” and he moves on “one step”, but the animation make “three or four step”.
I had try to play with the “Interruption Source”, but every entries make the same animation aka the full animation.
Is there a way to play the animation until the key is pressing down ? (Without code, only on animator)
I had already fix it via code. But I want it via interface.
This could be an issue concerning your Exit Time. This value defines how much of the animation is played until the transition to the next animation is started. “1” means it is played completely and “0” means the transition is started immediately if the conditions are true.
Additionally you can use the transition duration to smooth out the transition itself. I would recommend to play around with these values to see how they affect the animations.
#1 : At the end of the GIF, I’m quicky pressing the “D” button to move, and you can see that the animation is complete, even if I had release the button…
#2 : At the beginning of the GIF, you can see that sometimes, even if I’m on a ground, the checkbox “Ground” is check and sometime uncheck… Don’t know why…
#3 : Also sometimes, there are invisible wall, and my character is block…
#1
To me this seems to be a problem because you’re using GetAxis and not GetAxisRaw. GetAxis returns a value between -1 and 1 depending on the input. This value isn’t reached instantly but smoothly. So it needs a few frames until the final value is returned. The same smoothing happens after releasing the button.
Let’s say you’re pressing ‘D’ for a few seconds and then 1 is returned. When releasing the button in the next frame this value is for example 0.95. Then you press ‘D’ again an push that value back to 1.
The same thing happens when you’re quickly pressing ‘D’ starting with 0. The returned value will be slightly above 0 and the animation will be totally played.
To get this working you can use GetAxisRaw instead. It’s simply the same like GetAxis but without the smoothing. Then you would get -1, 0 or 1 as returned values.
I don’t know why the “has exit time” is automatically checked in Unity 5 and I don’t recall this in Unity 4.6. It actually messed my animations and their transitions from one state to another. I was going to reply to you to uncheck the box and to put the values of the offset and transition to 0 but you found it yourself
Although, I would like to be sure that we are not going to meet further issues with more complex animations than a simple idle to run, by unchecking the exit box and putting our settings to 0 instead of the default value set by Unity automatically. If a Unity Dev could jump in, it would be of great help !
For your #3, I would say that it may come from the position of your colliders and the collision detection but I’m not sure as it’s not happening all the time… For the feet, I like using a circle collider for example, helps smooth the movements somehow.
Hmmm, I will try to select a circle collider instead of a box one.
I had saw a lot of topics on unity3d forum and stackoverflow forum about the bounce/shake sprite when you move it. A lot of fixes are deploy by the community, like change some project settings parameters etc, but nothing is working for me.
I had also tried to change the “velocity method” by the “position.x” method, but same issue.
I guess I will put this issue on my checklist and trying to go ahead on my project. But if you have an idea, it will be the welcome