2016-04-12 75 views
-1

我希望將對象從A連續移動到B,如第1 A到B,然後B到A,然後再次A到B等等,這些都要提前感謝。我試過這個。使用翻譯連續移動對象

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

你應該需要使用Vector3.Lerp:

兩個向量之間的線性插值。

向量a和b之間的插值由插值t表示。 參數t被限制在[0,1]的範圍內。這是最常用的 找到一個點沿着兩個 終點之間的直線的路線的小部分(例如,逐漸移動的物體在這些點之間。(read this

雖然這裏實際的答案是代碼你可以看到:

  1. http://answers.unity3d.com/questions/14279/make-an-object-move-from-point-a-to-point-b-then-b.html
  2. http://answers.unity3d.com/questions/905966/moving-an-object-constantly-between-two-points-wit.html
  3. How to move an object between two points in Unity?
  4. http://answers.unity3d.com/questions/690884/how-to-move-an-object-along-x-axis-between-two-poi.html