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