Hi,
so in my game I’m creating a list of directional vectors and at certain points I need to find the average direction vector before that point. How can I find the average vector from a list?
Many Thanks,
Alec.
Hi,
so in my game I’m creating a list of directional vectors and at certain points I need to find the average direction vector before that point. How can I find the average vector from a list?
Many Thanks,
Alec.
You could try something like this:
using System.Collections.Generic;
Vector3 AverageVector(List<Vector3> vectorList){
Vector3 acumulateVector = Vector3.zero;
foreach (Vector3 v in vectorList){
acumulateVector += v;
}
return acumulateVector / vectorList.Count;
}