纳金网

标题: 关于时间函数的一些介绍 [打印本页]

作者: gqlu    时间: 2013-8-9 13:14
标题: 关于时间函数的一些介绍
http://gamedev.iteye.com/blog/1916736

这里作者提到对于Time这个类的一些使用情况。


我们可以通过调节Time.timeScale来控制游戏的快慢。但这个是有前提的,只有当我们的控制逻辑中含有Time.deltaTime的时候才会有放慢或者加快的效果。如果有个GameObject的移动是不受Time.deltaTime的控制,比如像这样的 newPosition.x += speed; 而不是这样 newPosition.x += Time.deltaTime * speed; 那么这个物体就不会放慢,也可以这么理解:Update()还是按照原来的速度来调用,但Time.deltaTime变慢了。


在时间变慢了之后,Physics的效果有时候看起来不是很好,有一卡一顿的感觉,
一种
可以通过设置interpolation;
另外一种
方法更加被作者推荐,那就是提高fixed time的时间精度,即Time.fixedDeltaTime (实际上这个值可以在project settings -> Physics里面来设置)


官方的文档里面也这么说道:
引用

If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.

Time.fixedDeltaTime = 0.02 * Time.timeScale;



timeScale变小,意味着速度变慢,而fixedDeltaTime也变小,却表示FixedUpdate()的调用次数增加了,这样精度更高了。这也隐含着FixedUpdate()的调用是收到timeScale控制的。


引用

Note that the fixedDeltaTime interval is with respect to the in-game time affected by timeScale.



此外,作者还用到了Mathf.Lerp()这个函数。这个是表示线性插值的计算。


StartCoroutine()之前有可能还需要StopAllCoroutines()。


把声音也调慢可以使用AudioSource.pitch这个值。






欢迎光临 纳金网 (http://c-www.narkii.com/club/) Powered by Discuz! X2.5