another "Cannot implicitly convert type `UnityEngine.Quaternion' to `UnityEngine.Vector3' " question

Hi ive been teaching myself a bit of C# over the holidays, and im quite pleased with the progress of my understanding of how to code as i have limited experience befor this.
having said that some things have completely stumped me due to my lack of basic knowledge about some areas, rotation being one…

anyway im trying to make a script to lerp an objects Z rotation when a button is pressed and lerp it back when it isnt pressed, i got the script working nicely with un-lerped rotations but want to take it to the next level and learn a bit more.

unfortunately ive hit a snag, and this is my first time working with quaternions AND lerps

im getting the error:
Assets/scripts/plane_anim.cs(40,48): error CS0029: Cannot implicitly convert type UnityEngine.Quaternion' to UnityEngine.Vector3’

code:

	public float banking;
	//public Transform from;
	//public Transform to;
	public float speed = 0.1f;
	
	// Update is called once per frame
	void Update ()
	{
		if(Input.GetAxis ("Horizontal") < 0) 
			//if button is pressed, perform the following
		{
			Quaternion targetRotationLeft = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , banking);
			Quaternion currentRotationLeft = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , transform.eulerAngles.z);
			//rotate the object to a specified angle
			//this.targetRotation = Quaternion.Euler(new Vector3(transform.eulerAngles.x , transform.eulerAngles.y , banking));
				this.transform.eulerAngles = Quaternion.Lerp(currentRotationLeft, targetRotationLeft , Time.time * speed);
		}
		if(Input.GetAxis ("Horizontal") == 0) 
			//if button is pressed, perform the following
		{
			Quaternion targetRotationLevel = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , 0);
			Quaternion currentRotationLevel = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , transform.eulerAngles.z);
			//rotate the object to a specified angle 
				this.transform.eulerAngles = Quaternion.Lerp(currentRotationLevel, targetRotationLevel , Time.time * speed);
		}

		if(Input.GetAxis ("Horizontal") > 0) 
			//if button is pressed, perform the following
		{
			Quaternion targetRotationRight = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , -banking);
			Quaternion currentRotationRight = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , transform.eulerAngles.z);
			//rotate the object to a specified angle
			//this.transform.eulerAngles = Quaternion.Lerp(new Vector3(transform.eulerAngles, targetRotationLeft , Time.time * speed)
				this.transform.eulerAngles = Quaternion.Lerp(currentRotationRight, targetRotationRight , Time.time * speed);

			//this.transform.eulerAngles = Quaternion.Lerp(new Vector3(transform.eulerAngles, tilt , Time.time * speed));
		}
	}
}

the line:
this.transform.eulerAngles = Quaternion.Lerp(currentRotationLeft, targetRotationLeft , Time.time * speed);
in its various forms is giving me all the issues, now i thought that i had it correct IE ive changed it all to quaternion, but ive obviously not, but im struggling to find out where im wrong ive tried alot of different things and none have worked out.

if anyone could point me in the right direction(s) i would be very greatful.

also im an artist by trade so im sure looking at my code is like looking at programmer at so apologies :wink:

Transform.eulerAngles is not a Quaternion. It is a Vector3. What you want is Transform.rotation. There are a couple of other issues in this line. You may want Slerp() instead of Lerp(). Plus you want ‘Time.deltaTime’, not ‘Time.time’. So the whole line would be:

transform.rotation = Quaternion.Slerp(currentRotationRight, targetRotationRight, Time.deltaTime * speed));

While the code you have here (with this problem fixed) will work, it can be simplified. Here is a bit of a rewrite:

public float banking = 45.0f;
public float speed = 1.1f;

private Quaternion qTo;

void Start() {
	qTo = transform.rotation;
}

void Update () {
	if(Input.GetAxis ("Horizontal") < 0)  {
		qTo = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , banking);
	}
	
	else if(Input.GetAxis ("Horizontal") > 0) {
		qTo = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , -banking);
	}
	else   {
		qTo = Quaternion.Euler (transform.eulerAngles.x , transform.eulerAngles.y , 0);
	}

	transform.rotation = Quaternion.Slerp (transform.rotation, qTo, Time.deltaTime * speed);
}

In addition, you might want to experiment with replacing Quaternion.Slerp() with Quaternion.RotateTowards(). The ‘speed’ parameter will need to be adjusted, but everything else should work fine.

As a final note, this code will not work for all rotation of the object. There are issues with reading eulerAngles. Because they are derived from the Quaternion (Transform.rotation), they can change representation on you. So if you are looking to make this work for arbitrary rotations, you will need to approach the problem a bit differently.