- Home /
Vector3.Lerp result in "laggy" movement while running on iOS devices
I know this question has been asked for many times but I've tried all the proposed solutions and none of them fix...
Possible solutions that I've tried: 1. Use FixedUpdate instead of Update 2. Use smoothDeltaTime instead of deltaTime 3. Use SmoothDamp instead of Lerp 4. Use LateUpdate instead of Update
void Update()
{
time += (Time.deltaTime / duration);
if (time > 1.0f)
time = 1.0f;
Vector3 newPos = Vector3.Lerp(startPos, endPos, time);
transform.position = newPos;
}
When I try to run it on iOS devices, it run very jaggy/laggy.. I remember last time when I was using Unity 3.x, it doesn't has this problem.
float duration = 3.0f;
Vector3 startPos;
Vector3 endPos;
float startTime;
void Start ()
{
startTime = Time.time;
endPos = new Vector3(-3,0,0);
}
void Update()
{
float moveTime;
moveTime = (Time.time-startTime)/duration;
if(moveTime < duration)
{
transform.position = Vector3.Lerp(transform.position,endPos,moveTime/duration);
}
}
Answer by Mr_Cad · Jan 09, 2014 at 05:59 AM
I think the problem was caused by the framerate. Th default given by Unity is 30. After setting it to 60 it runs smoothly now. it wasn't the code problem.
Answer by MrProfessorTroll · Jan 09, 2014 at 04:45 AM
private float time = 1.0f;
void Update()
{
transform.position = Vector3.Lerp(startPos, endPos, time);
}
You dont need to use Time.deltaTime with Vector3.Lerp. Good luck
How could that be possible? if u set the time = 1.0f, when the Lerp code is running the time is always = 1.0f I don't think that's correct.