[英]finding points along a vector in 3d
Vector3[] GetPointsInbetween(Vector3 a, Vector3 b, float offset){
int count = (int)((b - a).magnitude / offset);
Vector3[] result = new Vector3[count];
Vector3 delta = (b - a).normalized * offset;
for (int i = 0; i < count; i++) {
result[i] = a + delta * i;
Debug.Log(result[i]);
}
return result;
}
但是.magnitude
和.normalized
是非常昂貴的操作,盡量避免在Update()
使用它
您可以通過使用Vector3.MoveTowards
http://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html來完成它
我不熟悉 Unity 函數,但正式地描述了兩點之間的線性插值。 點A
和B
之間的線段可以用參數化形式來描述
A * s + B * (1-s)
其中s
來自區間[0,1]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.