# Moving my character/camera makes environnement jerky

I'm learning to make a Tilebased game with Unity and for that I use the Zelda alttp assets. I just have Tiles, a Camera and a moving Character with a rigidbody2D and a CircleCollider.

When the Camera follows the Character, the scene feels Jerky.

Info:

• The Camera uses the 2D Pixel Perfect package.
• The Character is moving via Rigidbody2D.MovePosition() in the FixedUpdate Method:

code:

void Update()
{
float yInput;
float xInput;

#region yMovement
if (Input.GetKey(keyMoveTop))
{
if (Input.GetKey(keyMoveBot))
{
yInput = 0f;
}
else yInput = 1f;
}
else if (Input.GetKey(keyMoveBot))
{
yInput = -1f;
}
else yInput = 0f;
#endregion

#region xMovement
if (Input.GetKey(keyMoveLeft))
{
if (Input.GetKey(keyMoveRight))
{
xInput = 0f;
}
else xInput = -1f;
}
else if (Input.GetKey(keyMoveRight))
{
xInput = 1f;
}
else xInput = 0f;
#endregion

//Walking
isWalking = Input.GetKey(keyMoveWalk);
moveDirection = Vector2.ClampMagnitude(transform.right * xInput + transform.up * yInput, 1f);
}

private void FixedUpdate()
{
_rb.MovePosition(_rb.position + moveDirection * (isWalking ? walkSpeed : runSpeed) * Time.fixedDeltaTime);
}


You can see the problem here: https://youtu.be/MA2zZPME5X4

Edit: Added all my movement code

• Have you looked at your framerate? Is it 60 fps (or whatever the refresh rate of your monitor is)? Jan 17 '20 at 19:11
• No I didn't but it would be very weird to not have max fps plying this "game" since it's a gaming computer ^^ Jan 17 '20 at 21:18
• @Foxwarrior Unity shows I have 70 to 80 fps during playmode Jan 17 '20 at 22:07
• Could it be a rounding problem in your movement code? Like if walkspeed was 0.6 pixels per frame, then it would appear to move 0,1,0,1,1,0,1,0,1,1 pixels in a given frame, and look very jerky. Or maybe it's because you're moving in FixedUpdate but rendering in Update, which aren't synchronized with each other. Jan 17 '20 at 22:21
• @Foxwarrior I removed the PixelPerfect component to the Camera (so I think there's nothing that rounds values now) the problem is still here :( Jan 17 '20 at 22:57

• @Sharpnel - Alright, then it sounds like a performance issue. Maybe you wrote some horrible code. Often a combination of instantiates, Debug.Log and wild loops. Look into: Unity Editor > Window > Analysis > Profiles (or Ctrl+7). See if there are weird spikes during runtime. If you can't figure it out, activate "Deep Profile." That may slow down everything, but you'll get pinpointed to the exact code part which causes performance issues and also some neat statistics. Alternative tool is to use System.Diagnostics.Stopwatch and test suspicious code parts. Jan 17 '20 at 23:10