0

I am trying to rotate a game object using the lerp command, however I am getting the following error:

error CS0029: Cannot implicitly convert type float' to UnityEngine.Quaternion'

This is the code I am using

box.rotation = Quaternion.AngleAxis(NewAngle, Vector3.right);
boxAngle = box.rotation.x;
targetAngle = 90.0f;
NewAngle = Mathf.Lerp(boxAngle, targetAngle, smooth * Time.deltaTime);

Could anyone point me in the right direction? What am I doing wrong?

1
  • A quarternion is not a rotation. Use a vector3 Commented Oct 12, 2014 at 22:31

1 Answer 1

4

Assuming box is an Transform, this should work, but if you're rotating only on one axis it will be much easier to use

box.eulerAngles=new Vector3(NewAngle, 0f, 0f);

Also, there other two potential issues:

  1. lerping after it's set - you've got a potential one frame lag
  2. gimbal lock or modulo 360 problems (think how will 350 lerp to 90 - it will go the long way around)

How about:

Quaternion targetAngle=Quaternion.Euler(90f, 0f, 0f);
box.rotation=Quaternion.Lerp(box.rotation, targetAngle, Time.deltaTime*smooth);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.