I want to move an object from A to B continuously,like 1st A to B then B to A then again A to B and so on,thanks in advance. I've tried this.
float speed X = 1; float speed Y = 0; float speed Z = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (new Vector 3 (speed X, speed Y, speed Z) * Time . delta time );
}
答案 0 :(得分:0)
您应该使用Vector3.Lerp:
在两个向量之间进行线性插值。
通过插值t在矢量a和b之间插值。该 参数t被钳位到[0,1]范围内。这是最常用的 沿着两条线之间的线找到一个点的一部分 端点(例如,在这些点之间逐渐移动对象。(read this)
虽然您的实际答案是代码,但您可以看到: