我有一个空的游戏对象,里面装满了我所有的玩家组件,在它里面是一个模型,当控件被按下时,这个模型会被GetButtonDown实例化。目前,玩家游戏对象中的所有内容都会立即移动到下一个点(基本上是在没有过渡的情况下传送到那里)。有什么办法我可以让它全部通过,比如说1秒,而不是立即去那里?下面是在GetButtonDown上发生的事情
    if (Input.GetButtonDown ("VerticalFwd"))
    {
        amountToMove.y = 1f;
        transform.Translate (amountToMove);
    }我尝试过transform.Translate (amountToMove * Time.deltaTime *随机化);以及各种使用时间的方法,然而,这似乎不起作用,尽管这似乎是最符合逻辑的方法。我猜是因为GetButtonDown只在按下它时才“运行”,并且没有更新功能来“计时”移动每一个帧?有什么想法吗?amountToMove也被保存为Vector3。
发布于 2013-12-19 02:19:51
试试.Lerp,它作为一个协同线运行,在一定时间内插入一个值Vector3.Lerp(Vector3 start,Vector3 end,float time)
见文档这里
这应该能让你对发生的事情有一个大致的了解。
Vector3 Distance = End - Start; 
// this will return the difference 
this.transform.position += Distance/time.deltatime * Movetime 
// this divides the Distance equal to the time.deltatime.. (Use Movetime to make the movement take more or less then 1 second如果距离是1x.1y.1z,而time.deltatime是.1,移动时间是1.你得到一个.1xyz的运动,每一个滴答,花1秒到达终点。
FYI: transform.Translate作为一个花哨的.position +=工作,为此您可以互换使用它们。
编辑这里有几个解决方案
简单::
Vector3 amountToMove = new Vector3(0,1,0); //  Vector3.up is short hand for (0,1,0) if you want to use that instead
if (Input.GetButtonDown ("VerticalFwd"))
    {
        transform.position = Vector3.Lerp(transform.position ,transform.position + amountToMove, 1);
    }很难而且可能是不必要的:
为您的特定应用程序见这里的文档编写一种线性插值的Coroutine
https://stackoverflow.com/questions/20672170
复制相似问题