- Home /
Movement stutter when Animator is activated in 2D project (4.3)
Hi,
In my top-down 2D game, whenever I activate the Animator on my player (in the inspector), the movement of the player begins to stutter. When the Animator component is deactivated his movement is really smooth.
It is quite strange as there is no significant change in the framerate when there is stuttering or fluid movement. According to the profiler does the Animator.Update() only account for anywhere between 1.5% and 2.5% of the CPU usage when the movement is stuttering.
The player consist of eight different sprites (body, head, 2x upper arm, 2x lower arm, 2x hand) that are animated using curves in the Dope Sheet. All the sprites (limbs) are nested under an empty gameobject that contains a rigidbody2d component and a polygon collider (as well as some scripts). The limbs only have a SpriteRenderer attached.
The Animation Controller contains three different animations, idle, walk and shoot. They are made up of somewhere between 5 and 7 different animation curves that mostly changes the rotation of the limbs (you can see the dope sheet for the walk animation in the attached image). They transition between each other based on the player speed and a trigger (when the player shoots).
I have tried to set the Fixed Timestep to 0.01 instead of 0.02, which helped a bit. It is not as good as I would like it to be, and I'm a bit uncomfortable to set it much lower than that.
The player movement is controlled using AddForce() in FixedUpdate() as shown below, if that should be of any importance.
It seems strange if Unity has trouble handling this, as it does not appear to be very computational demanding. Does anyone have a suggestion as to how I can get proper movement using this animation system?
Also, check out this video for a comparison between the movement when the animator is on and off: https://www.dropbox.com/s/ko68hlazdt9jixr/comparison.mov (the player limb graphics are placeholder).
void FixedUpdate () {
device = InputManager.ActiveDevice; // we're using InControl
float h = device.LeftStickX;
float v = device.LeftStickY;
if(gameObject.rigidbody2D.velocity.x < maxSpeed)
gameObject.rigidbody2D.AddForce(Vector2.right * h * maxSpeed * force * Time.fixedDeltaTime);
if(gameObject.rigidbody2D.velocity.y < maxSpeed)
gameObject.rigidbody2D.AddForce (Vector2.up * v * maxSpeed * force * Time.fixedDeltaTime);
if(device.RightStickX != 0 || device.RightStickY != 0)
angle = new Vector3(0.0f, 0.0f, (Mathf.Atan2(device.RightStickX*-1, device.RightStickY) * Mathf.Rad2Deg));
transform.localRotation = Quaternion.Euler(angle); // this should probably be in Update(), but it does not seem to cause any trouble atm
}
The problem is not the animator. You have 2 forces acting on the same character. You need your animations to NOT move the character. I think you can easily do this by turning off 'Root$$anonymous$$otion' on the animator.
Hi ZenithCode,
I have Apply Root $$anonymous$$otion deselected in the Animator, so that is not the problem, unfortunately.
I have tried selecting Animate Physics, which helps on the uneven movement speed, however there is still a jitter/shaking effect whenever the player moves.
I'm also interpolating the rigidbody2d, so thats neither the issue.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143503im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I iterate all animation clips used by an Animator? 2 Answers
Whever I try to change an Animator value in my script, it becomes incredibly laggy [C#] 1 Answer
Precise animation control 4 Answers
"Empty" Animator transition is overriding other trigger based transition 1 Answer
Can't manually rotate bones in inspector or through script. 2 Answers