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