Getting points within a radius to place burn decals from an explosion

This image should illustrate what I want:
alt text

Here is the code I have at the moment:

public void MakeBurns(Vector3 position)
{
	// find all objects within radius
	RaycastHit[] hits = Physics.SphereCastAll(position, burnRadius, Vector3.down, 0);

	if (hits.Length < 1)
		return;

	// burn each hit
	foreach (RaycastHit hit in hits)
	{
		Vector3 point = hit.point;
		Vector3 normal = hit.normal; // I'm fairly certain this is the wrong normal, but I'll figure that out later

		// move away from point
		point += normal.normalized*offsetFromHit;

		pool.LoadObject(point, normal);
	}
}

I can think of two ways of approaching this problem. For the first one you start with a Physics.OverlapSphere(). This will give you a list of game object where the bounding box for the collider is within your explosion area. Then you will need to process the mesh to determine the closest point on that game object to the center of the explosion. Here is a link with some source for calculating that point:

http://answers.unity3d.com/questions/424974/nearest-point-on-mesh.html

Note you will need to check the distance to make sure it is within the sphere distance since OverlapSphere() bases its results on the bounding box.

The second solution is to do a sphere of raycasts. Here is one question dealing with that issue:

http://answers.unity3d.com/questions/410992/how-do-i-get-raycasts-to-cast-symmetrically.html

The UniformPointsOnSphere() will generate the directions for all the raycasts. The numberOfPoints will determine the number of raycasts you do. If you only want want one decal per object, you will need to sort through the result and find the closest hit for each object hit.

Using Robertbu’s advice, I created this. When using 10 raycast accuracy, it took an average of 5.2E-5 seconds to complete, and when using 1000 casts, it took on average 0.07 seconds (these times do not include the pool loading). I found I good results with 20 raycasts.

I will later add script to scale up and fade burn marks depending on the distance from the explosion, but that should be easy.

// (found at http://answers.unity3d.com/questions/410992/how-do-i-get-raycasts-to-cast-symmetrically.html)
Vector3[] rayDirections = UniformPointsOnSphere(raycasts);

// ALL hits on each object hit
var allHits = new Dictionary<GameObject, List<RaycastHit>>();

// find all objects to burn
foreach (Vector3 dir in rayDirections)
{
	// move dir back a tiny bit so the rays can hit objects at the given position
	Vector3 backedUpPos = position - dir*0.1f;

	RaycastHit hit;
	if (Physics.Raycast(backedUpPos, dir, out hit, burnRadius)) // may need RaycastAll
	{
		GameObject hitObject = hit.collider.gameObject;

		// if the object doesn't have a list already, add it
		if (! allHits.ContainsKey(hitObject))
			allHits.Add(hitObject, new List<RaycastHit>());

		// add the hit the the right list
		List<RaycastHit> list = allHits[hitObject];
		list.Add(hit);
	}
}

// find the closest point for each gameobject
List<RaycastHit> burnHits = new List<RaycastHit>();
foreach (List<RaycastHit> hits in allHits.Values)
{
	RaycastHit currentClosest = hits[0];
	float closest = Mathf.Infinity;

	// for each hit of this gameobject
	foreach (RaycastHit hit in hits)
	{
		float distance = Vector3.Distance(hit.point, position);
		if (distance < closest)
		{
			currentClosest = hit;
			closest = distance;
		}
	}

	// burn!
	Vector3 hitPos = currentClosest.point + currentClosest.normal*offsetFromHit;
	pool.LoadObject(hitPos, currentClosest.normal);
}