给定两个 Vector3 坐标p1
和p2
,我们可以计算它们之间均匀分布的 X 点:
Vector3 p1 = <some vector>
Vector3 p2 = <some vector>
int numPoints = 9;
float step = 1f / (numPoints+1);
for (float perc = step; perc < 1f; perc += step) {
Vector3 v = Vector3.Lerp(p1, p2, perc);
//do something at position v
}
或者我们可以计算几个点,每个点最多间隔 X 个单位:
Vector3 p1 = <some vector>
Vector3 p2 = <some vector>
float maxSpacing = 10f;
Vector3 diff = p2 - p1;
Vector3 dir = diff.normalized;
float totalDistance = diff.magnitude;
for (float dist = maxDistance; dist < totalDistance; dist += maxSpacing ) {
Vector3 v = p1 + dir * dist;
//do something at position v
}
(刚刚注意到我的示例代码在 C# 中,您之前的问题是使用 JS;大概您可以找出区别?)