Add rotation to LookAt (CarSmoothFollow) ?

Hi,

I would like to add a rotation to the camera, which already uses a LookAt method. When I add this code to a file :

void Update () {
		float newZ = Input.GetAxis("Horizontal") * -1 * 25;
		Vector3 rotEnd = new Vector3( 0, 0, newZ );
		transform.eulerAngles += rotEnd;
	}

the camera does not rotate with the horizontal axis because of the lookAt method in the CarSmoothFollow script. I am trying to add it directly in the lookAt method, but it does not work correctly, it kind of repeats the rotation 100 times per second. Would you know how to do this? Here is the code :

	void LateUpdate () {
		wantedHeight = target.position.y + height;
		currentHeight = transform.position.y;
		
		//HORIZONTAL
		float newZ = Input.GetAxis("Horizontal") * -1 * 25;
		Vector3 rotEnd = new Vector3( 0, 0, newZ );
		//transform.eulerAngles += rotEnd;
 
		wantedRotationAngle = target.eulerAngles.y;
		currentRotationAngle = transform.eulerAngles.y;
 
		currentRotationAngle = Mathf.SmoothDampAngle(currentRotationAngle, wantedRotationAngle, ref yVelocity, rotationSnapTime);
 
		currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
 
		wantedPosition = target.position;
		wantedPosition.y = currentHeight;
 
		usedDistance = Mathf.SmoothDampAngle(usedDistance, distance + (parentRigidbody.velocity.magnitude * distanceMultiplier), ref zVelocity, distanceSnapTime); 
 
		wantedPosition += Quaternion.Euler(0, currentRotationAngle, 0) * new Vector3(0, 0, -usedDistance);
 
		transform.position = wantedPosition;
		transform.LookAt(target.position + lookAtVector + rotEnd);//wrong
	}

Thanks

It is hard to make a best fix without knowing the geometry of your situation. Let me answer the specific question you ask. I think you want:

transform.LookAt(target.position + lookAtVector);
transform.eulerAngles += rotEnd;

Note that given you have a look at vector (instead of a position), you can do this:

  transform.roation = Quaternion.LookRotation(lookAtVector);
  transform.eulerAngles += rotEnd;

And you should be able to combine the two concepts like this (untested):

transform.rotation = Quaternion.Euler(rotEnd) * Quaternion.LookAt(lookAtVector);