I have few animations that work similar to this:
IEnumerator MoveObjTo(GameObject obj1, GameObject ob2, float time)
{
var start = obj1.transform.position.x;
var end = obj2.transform.position.x;
float passedPath = 0f;
var s = end - start;
float speed = (end - start) / time;
while (passedPath < s)
{
var ds = speed * Time.deltaTime;
var newPos = obj.transform.position;
newPos.x += ds;
obj.transform.position = newPos;
passedPath += ds;
yield return new WaitForEndOfFrame();
}
}
It worked fine until I added this line to my code:
Application.targetFrameRate = 60;
After this, inside the Unity editor animation started to work 10 times faster (it's still OK on device). And I noticed that if I set targetFrameRate
to the same FPS value as shown in the editor's Stats (400 FPS), to the animation speed is fixed.
If I print Time.deltaTime
and ds
inside this method, I'll get about the same values and it looks like Time.timeDelta is always 0.017
, but with different targetFrameRate
values that same 0.017 corresponds to different real time intervals.
I'll fix it by ifdef
ing the targetFrameRate
setup, I'm just curious how this works.
Time.deltaTime
can vary wildly and may represent several seconds per frame. Are the fast animations purely in the editor view? Or also when in Play mode? \$\endgroup\$