- Home /
Using Lerp to look up with your local camera?
Hi, so I've been using lerp for the first time and I'm a bit confused. Here's my code;
if (Input.GetAxis("Mouse Y") > .1f & disableMotion == 0)
{
cameraobj.transform.localPosition = new Vector3(.9f, Mathf.Lerp(4, 7, Time.deltaTime), -4.5f);
}
I plan on modifying the rotation of X later, but I wanted to figure out what I'm doing first. This code is being run within Void Update of course. Am I using the wrong kind of Lerp?
The result is an instantaneous .5f jump in my Y Axis and then it just stops. I think it's probably because I'm using = new Vector3, but I have to run to work now unfortunately and the scripting reference told me to use = new Vector3. Thanks for the help guys.
Answer by Hellium · Jul 30, 2015 at 05:44 PM
Read the explanation I gave here :
http://answers.unity3d.com/questions/998544/having-difficulty-with-lerp.html
I don't like the example Unity gave about LERP.
For your problem, here is a simple example :
private float t = 0 ; // Parameter of the Lerp
private float duration = 5 ; // Duration of the lerp transition = 5 seconds
void Update()
{
....
if (Input.GetAxis("Mouse Y") > .1f && disableMotion == 0)
{
if( t > duration )
t = 0 ;
cameraobj.transform.localPosition = new Vector3(.9f, Mathf.Lerp(4f, 7f, t / duration), -4.5f);
t += Time.deltaTime ;
}
else
t = 0 ;
...
}
Your answer
Follow this Question
Related Questions
Lerping orthographic camera size jitters 1 Answer
Smooth camera shift, Lerp? SmoothShift? 2 Answers
Shader works on Android but it is black on iOS 1 Answer
Changing camera position to shoot through scope on gun 1 Answer
Mouse wheel zoom 1 Answer