So I’m trying have it that when an explosion happens, a bunch of rays are sent out in a sphere, and depending on the properties of what they hit, they will deduct HP, stop moving, continue moving, etc. So what would the most effective way of doing this be? Also, I’m trying to figure out what resolution of rays I will need to be accurate enough to get an effective reading. Any help would be great!
Edit: I’m trying to make the explosion realisticish, so rather then hurting everything in a radius, the explosion has the possibility to be physically blocked by armor. This is why I’m thinking rays are the best, as I would be using them as “explosion probes”, functioning as the moving explosion.
void Update ()
{
Ray ray = new Ray();
ray.origin = Vector3.zero;
float inverseResolution = 10f;
Vector3 direction = Vector3.right;
int steps = Mathf.FloorToInt(360f / inverseResolution);
Quaternion xRotation = Quaternion.Euler (Vector3.right * inverseResolution);
Quaternion yRotation = Quaternion.Euler(Vector3.up * inverseResolution);
Quaternion zRotation = Quaternion.Euler(Vector3.forward * inverseResolution);
for(int x=0; x < steps/2; x++) {
direction = zRotation * direction;
for(int y=0; y < steps; y++) {
direction = xRotation * direction;
Debug.DrawLine(ray.origin,ray.origin+direction); // for science
}
}
}
Resolution’s hard to say. You can do more casts if you split them into several frames using a coroutine. You could also do a sphere-overlap, then cast to the corners/center of any target objects. If you hit, great, if you miss, expand the cast zone a bit and try again. (Basically cone-cast towards the target with expanding radius until you’re casting outside of the target’s bounds or you hit it)