I realize this question has been asked and I’ve seen them and followed what they said, but it’s still not working. I even watched some YouTube tutorials. I’ll post my code below.
What I’m wanting to do is to rotate and move my camera when I press a key. When I let up the key, I want to return to my initial camera. This works if I’m just using Vector3.Lerp, however I want to be able to rotate as well because it will look better. Thank you!
using UnityEngine;
using System.Collections;
public class LeanLeftRight : MonoBehaviour {
public Transform leanLeft;
public Transform leanRight;
public Transform cam;
public Transform initCam;
void LeanLeft()
{
Debug.Log("LeanLeft");
//FVAPI.lerpVectorAndQuaternionTimeMultiplied(cam, leanLeft, 5);
cam.rotation = Quaternion.Slerp (cam.rotation, leanLeft.rotation, 1);
/* The code above that is commented out is the same as below except I'm
* making the Slerping automatic instead of over time, just wanted
* to make that clear.
*/
}
void LeanRight()
{
Debug.Log("LeanRight");
//FVAPI.lerpVectorAndQuaternionTimeMultiplied(cam, leanRight, 5);
cam.rotation = Quaternion.Slerp (cam.rotation, leanRight.rotation, 1);
}
void LeanBack()
{
Debug.Log("LeanBack");
//FVAPI.lerpVectorAndQuaternionTimeMultiplied(cam, initCam, 4);
cam.rotation = Quaternion.Slerp (cam.rotation, initCam.rotation, 1);
}
void Update()
{
if(InputManager.GetKey("leanLeft"))
LeanLeft();
else if(InputManager.GetKey("leanRight"))
LeanRight ();
else
LeanBack();
}
}