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()
您可以通过使用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. The line segment between the points A
and B
can be described by the parameterized form
A * s + B * (1-s)
where s
is from the interval [0,1]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.