protected void DetermineDirections(Vector3 path) { float maxDot = 0; int maxIndex = -1; float diff = 1; for (int i = 0; i < 4; i++) { diff = Vector3.Dot(path, (Vector3)Entity.directionVectors [i]); if (diff > maxDot) { maxDot = diff; maxIndex = i; } } entity.SetDirs(maxIndex + 1, true); int lowerIndex = ((maxIndex - 1 % 4) + 4) % 4; diff = Vector3.Dot(path, (Vector3)Entity.directionVectors [maxIndex] + Entity.secondaryDirFactor * (Vector3)Entity.directionVectors [lowerIndex]); if (maxDot < diff) { entity.SetDirs(lowerIndex + 1, false); maxDot = diff; } int higherIndex = (maxIndex + 1) % 4; diff = Vector3.Dot(path, (Vector3)Entity.directionVectors [maxIndex] + Entity.secondaryDirFactor * (Vector3)Entity.directionVectors [higherIndex]); if (maxDot < diff) { entity.SetDirs(higherIndex + 1, false); } }