List<Vector2>[] calculateMapCollision(Vector2[] endPos,Vector2[] v)
{
List<Vector2>[] result = new List<Vector2>[2];
Vector2[] newV = new Vector2[2];
Vector2[] nextEndPos = new Vector2[2];
List<Vector2>[] nextResult = new List<Vector2>[2];
// Examine collision with map elements
for (int i=0; i<2; i++) {
result[i]= new List<Vector2>();
if (bManager.isOccupied (endPos [i])) {
newV [i] = -v [i];
// Going half the distance before collision
result [i].Add (v [i]/2);
// Prepare for recursion
nextEndPos [i] = endPos [i] + newV [i];
}else{
nextEndPos [i] = endPos [i];
newV[i] = Vector2.zero;
}
}
nextResult = calculateCollision(nextEndPos,newV);
// Correct the first element
result[0].Add(v[0]/2+nextResult[0][0]);
result[1].Add(v[1]/2+nextResult[1][0]);
nextResult[0].RemoveAt(0);
nextResult[1].RemoveAt(0);
// Merge the lists
result = appendLists(result,nextResult);
return result;
}