- Home /
Accurate timing while using timeScale.
I have an entity moving between multiple waypoints using iTween. I would like to use timeScale to speed up/slow down the global time. I have a timer that increments based on deltaTime (timer += Time.deltaTime). When I run at timeScale 1 the entity gets to the waypoints at a certain time. When I change the timeScale the entity does not reach the waypoints at the same time. For example at timeScale 1 my entity reaches the waypoint in 1 min. At timescale 20 it reaches at 1min and 15 seconds. Is there a more accurate way of keeping track of time if I need to speed up the game play.
Answer by Kiloblargh · Jul 03, 2013 at 10:40 PM
startTime = Time.time;
...
timer = Time.time - startTime;
is always better to use than
timer = 0;
...
timer += Time.deltaTime;
I tried what you suggested but I get the same amount of error. The project i'm working on requires the users to fast forward and rewind while keeping track of time consistently and accurately. There seems to be a linear drift basted the current timeScale value.
I was about to ask the same question! I have a similar problem with an agent using Navmesh.
I added a timer to see how long it takes him to complete the task:
if (playerProperties.currentTask == GoToSleep){
taskTotalTime += Time.deltaTime;
}
If timeScale = 1 I get a taskTotalTime = 17.5secs
If timeScale = 80 I get a taskTotalTime = 71.5secs
I've also tried to fluctuate between different timeScales and always get different results. I cant figure out what "system" is getting broken with the timeScale changes...