Obstacle Avoidance Behavior
rayVector[1] = new Vector3(Mathf.Cos(rightRayOrientation), 0,
Mathf.Sin(rightRayOrientation));
rayVector[1].Normalize();
rayVector[1] *= lookahead;
rayVector[2] = new Vector3(Mathf.Cos(leftRayOrientation), 0,
Mathf.Sin(leftRayOrientation));
rayVector[2].Normalize();
rayVector[2] *= lookahead;
for (int i = 0; i < rayVector.Length; i++){
RaycastHit hit;
if (Physics.Raycast(transform.position, rayVector[i], out hit,
lookahead)){
Vector3 target = hit.point + (hit.normal * avoidDistance);
steering.linear = target - transform.position;
steering.linear.Normalize();
steering.linear *= steeringbase.maxAcceleration;
break;
}
}
return steering;
}
}