[英]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;
}
but .magnitude
and .normalized
are very expensive operations, try to avoid using this in Update()
但是
.magnitude
和.normalized
是非常昂贵的操作,尽量避免在Update()
使用它
您可以通过使用Vector3.MoveTowards
http://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html来完成它
I'm not familiar with the Unitiy functions, but formally you describe linear interpolation between the two points.我不熟悉 Unity 函数,但正式地描述了两点之间的线性插值。 The line segment between the points
A
and B
can be described by the parameterized form点
A
和B
之间的线段可以用参数化形式来描述
A * s + B * (1-s)
where s
is from the interval [0,1]
.其中
s
来自区间[0,1]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.