how can i avoid the rotation effect of the camera being the child of the player? #c

Dear programers of unity,
I am in a situation where finding the solution for the problem seems a bit hard. my game character is floating upwards with negative gravity. i would like the camera to follow the player going upwards and off course sideways. due to the fact that my character is leaning left and right when going sideways, the camera is following that behavior as well being a child. i would like it to only ignore the leaning part while being a child or having a separate code so it isn’t really necessarily for the camera to be a child of the player.

i have searched on this site and even though the answers seemed logical, it didn’t worked out for me.

do you have any suggestions for me to solve this problem?

can you maybe also give me directions how to implement it as i am not really experienced with coding in this begin code:

using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Thank you in advance!

using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {
	
	Quaternion rotation;
	
	void Awake()
	{
		rotation = transform.rotation;
	}
	
	void LateUpdate()
	{
		transform.rotation = rotation;
	}
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

Found it myself :)

using UnityEngine;

class CameraFollow : MonoBehaviour
{

	private Vector3 startPos;
	private GameObject player;
	float zDistance;
	
	void Start()
	{
		player = GameObject.FindWithTag("Player");
		startPos = transform.position;
		zDistance = startPos.z - player.transform.position.z;
	}
	
	void Update()
	{
		Vector3 newPos = new Vector3(player.transform.position.x, startPos.y, player.transform.position.z + zDistance);
		transform.position = newPos;
	}
}

Add this script to the camera. Camera should not be child of player.