[英]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.