Camera problems when using animations and physics

Hi there.

I am making a side scrolling game and I’ve run into an issue with my camera. The camera is shaking/is jerky. Note that I have the rigid body set to interpolate.

I do all the physic stuff in FixedUpdate and all the cam stuff in LateUpdate.

Here is the problem.

If I have the camera in Late update the scene looks fine but when I move the character the camera renders him jaggy. All other animation stuff (not handled with physics) look fine.

If I try to move the camera logic to Fixed Update all the effects are reversed. It does not metter if I track the rigidbody or if I track a child transform of it. The effects are the same. Changing the rigidbody interpolation still does not change anything. I hope you can help me.

PlayerLogic

void FixedUpdate () 
	{
		if (grounded) 
		{
			doubleJump = false;
		}
		grounded = Physics.CheckSphere(groundCkeck.position, groundRadius, whatIsGround);


		rigidbody.velocity = new Vector2 (moveDirection * maxSpeed, rigidbody.velocity.y);

		if (moveDirection > 0.0f  !facingRight) 
		{
			Flip();
		}

		if (moveDirection < 0.0f  facingRight) 
		{
			Flip();
		}
	}
	
	// Update is called once per frame
	void Update () 
	{	
			
		if (Input.GetButton ("Fire1")   Time.time > nextFire) 
		{   nextFire = Time.time + fireRate;
			anim.Play(attackState);
		} 


		if (moveDirection == 0  grounded) 
		{
			anim.SetBool("Idle", true);
		}
		else
		{
			anim.SetBool("Idle", false);
		}


		moveDirection = Input.GetAxis ("Horizontal");

		if (Input.GetButtonDown ("Jump")  (grounded || !doubleJump)) 
		{
			Debug.Log(rigidbody.velocity);
			rigidbody.velocity += new Vector3(0, jumpHeight, 0) ;
			//rigidbody.AddForce(new Vector2(0, jumpSpeed)); //use this if the above method does not work

			anim.SetBool ("Jump", true);

			if(!doubleJump  !grounded)
			{
				doubleJump = true;
			}
		}
		else 
		{
			anim.SetBool ("Jump", false);
		}

		if(grounded)
		{
			anim.SetFloat ("MoveDirection", Mathf.Abs (moveDirection));

		}

		else
		{
			anim.SetFloat ("MoveDirection", 0);

		}

CameraLogic

void LateUpdate () {

		transform.position = new Vector3 (target.position.x, target.position.y, transform.position.z);
	
	}

You could watch the Unity’s 2d Slider video with Mike, they made something like this.

If I remember correctly he is using a static camera (not moving). My problem happens only if the camera moves/follows the player.

Tried to put all the players code into fixed update. Still no progress.

P.S: the target is an empty GO parented to the player.

Hello mate ,
i’ve made few sidescroller games with a similar setup for the camera like you did here , but i’ve never experienced the camera to render the player jaggy like you had

try to put the camera related code into Update() Method , since LateUpdate() is useful for tracking object that moves inside Update()

also try to multiply position values with Time.deltaTime :slight_smile:

mFatah thanks for the suggestion. The shake is still there >.<