Hello, I am using lerp to interpolate between two positions. The interpolation should be finished after 10 seconds, but it reaches the final position after about 1.6 seconds. I can' t figure out, what I am doing wrong. Any hints? Code (csharp): private var m_currentTime=0.0; private var m_timeToMove = 10.0; private var m_newPosition : Vector3; function Start() { while (m_currentTime < m_timeToMove){ m_currentTime += Time.deltaTime; transform.localPosition = Vector3.Lerp (transform.localPosition,m_newPosition, m_currentTime /m_timeToMove); print (" pos: " + transform.localPosition + " t: " + m_currentTime/m_timeToMove ); yield; } } function SetPosition(l_position){ m_newPosition = l_position; }
It's because you're continuously changing transform.localPosition each frame and using that as the first parameter in Lerp. You'd want to declare a "startPos = transform.position" variable before the loop, and use startPos instead of transform.position in the Lerp. (It's likely you actually meant transform.position rather than transform.localPosition.) --Eric
Eric thanks; with use of startPos, it is running correct. I am using localPosition because I would like to change the position relativ to the parent. Should be ok?
Yes, that's fine. I see localPosition used incorrectly sometimes, but not in this case it seems. --Eric