为什么Time.deltaTime不等于Input.accelerationEvents所有元素中element.deltaTime的和?
Why isn't Time.deltaTime equal to the sum of element.deltaTime in all the elements of Input.accelerationEvents?
Time.deltaTime
为您提供最后一帧经过的时间。
Input.accelerationEvents
包含加速度计的最后读数及其时间的数组。
我猜
totalTime = 0;
foreach (AccelerationEvent element in Input.accelerationEvents){
totalTime +=element.deltaTime;
}
结果将等于 Time.deltaTime,但事实并非如此。我错过了什么?
这是他们在 Unity 文档中关于加速度计的说法 http://docs.unity3d.com/Manual/MobileInput.html
Unity samples the hardware at a frequency of 60Hz and stores the result into the >variable. In reality, things are a little bit more complicated – accelerometer >sampling doesn’t occur at consistent time intervals, if under significant CPU >loads. As a result, the system might report 2 samples during one frame, then 1 >sample during the next frame
另外别忘了
AccelerationEvent.deltaTime is Amount of time passed since last accelerometer measurement.
And Time.deltaTime is the time in seconds it took to complete the last frame.
这些值是独立的,没有理由让它们彼此相等。
AccelerationEvent.deltaTime
变量 returns 自设备加速度计上次采样以来的时间量。然而,这种采样不能保证与游戏帧率同步(即使两者都旨在达到 60Hz),因此一帧期间所有 Input.accelerationEvents
的 deltaTime
的总和可能不等于 Time.deltaTime
那个帧。
the Unity documentation 提到了类似的内容:
[...] In reality, things are a little bit more complicated – accelerometer
sampling doesn’t occur at consistent time intervals, if under
significant CPU loads. As a result, the system might report 2 samples
during one frame, then 1 sample during the next frame.
一种可视化方法如下(假设每个破折号是一个任意时间单位):
Frames completed:
1-----2-----3-----4-----5-----6-----7-----8-----9-----
Accelerometer samples made:
1-----2-----3-----4------5-----6---7-----8-----9-----
请注意,虽然 frame6
正在完成,但 sample6
和 sample7
都已完成。然而,虽然frame6.deltaTime
= 5,但sample6.deltaTime + sample7.deltaTime
的总和= 5 + 3 = 8。因此,他们的时间不匹配。
希望对您有所帮助!如果您有任何问题,请告诉我。
Time.deltaTime
为您提供最后一帧经过的时间。
Input.accelerationEvents
包含加速度计的最后读数及其时间的数组。
我猜
totalTime = 0;
foreach (AccelerationEvent element in Input.accelerationEvents){
totalTime +=element.deltaTime;
}
结果将等于 Time.deltaTime,但事实并非如此。我错过了什么?
这是他们在 Unity 文档中关于加速度计的说法 http://docs.unity3d.com/Manual/MobileInput.html
Unity samples the hardware at a frequency of 60Hz and stores the result into the >variable. In reality, things are a little bit more complicated – accelerometer >sampling doesn’t occur at consistent time intervals, if under significant CPU >loads. As a result, the system might report 2 samples during one frame, then 1 >sample during the next frame
另外别忘了
AccelerationEvent.deltaTime is Amount of time passed since last accelerometer measurement. And Time.deltaTime is the time in seconds it took to complete the last frame.
这些值是独立的,没有理由让它们彼此相等。
AccelerationEvent.deltaTime
变量 returns 自设备加速度计上次采样以来的时间量。然而,这种采样不能保证与游戏帧率同步(即使两者都旨在达到 60Hz),因此一帧期间所有 Input.accelerationEvents
的 deltaTime
的总和可能不等于 Time.deltaTime
那个帧。
the Unity documentation 提到了类似的内容:
[...] In reality, things are a little bit more complicated – accelerometer sampling doesn’t occur at consistent time intervals, if under significant CPU loads. As a result, the system might report 2 samples during one frame, then 1 sample during the next frame.
一种可视化方法如下(假设每个破折号是一个任意时间单位):
Frames completed:
1-----2-----3-----4-----5-----6-----7-----8-----9-----
Accelerometer samples made:
1-----2-----3-----4------5-----6---7-----8-----9-----
请注意,虽然 frame6
正在完成,但 sample6
和 sample7
都已完成。然而,虽然frame6.deltaTime
= 5,但sample6.deltaTime + sample7.deltaTime
的总和= 5 + 3 = 8。因此,他们的时间不匹配。
希望对您有所帮助!如果您有任何问题,请告诉我。