How Do You Create a Custom Radial Object or Particle?

OK, I have been looking into this for a week and for the life of me I can’t find a good answer. What I want to do is from a fixed point create a circle with a custom radius. Here is the problem; I have to be able to control how much of the circle is created. And I would have to be able to script it to react to things on the point of collision.

EX1: From the front of a space ship a shield is projected that only covers 90 degrees of a circle.

EX2: A mage casts a spell that starts to create a circle on a wall but gets interrupted; making it so it only creates a percentage of a circle based on how long he spent.

Part of the problem is, is that I am not too sure what would be most effective for this, that’s why I left it vague. I can work with most kinds of coding and unity variables. So ultimately the answer would be whatever is most effective.

But if I had to give answer it would be: a curved line segment, the collection grows with the arc size, a filled mesh in that would be in the shape of a piece of pizza. With cords at 3 points, the center point of the circle then at the ends of the arcs.

Please post non-answers as comments. Thanks,

Regardless of the resultant format, at some point or another, you’ll want an algorithm that can take a radius, direction, and a percentage (of a circle), and return a mesh or whatever you want. For instance, for a 90 degree arc 5 units in front of an object, you’d be able to ask for

Mesh mesh = GenerateArcMesh( 5f, transform.forward, 0.25f );

Optionally you could have a parameter to achieve different vertex densities for finer control over cost vs accuracy, code which assigns UVs to the mesh so you can texture it, etc. Or alternate methods which accept two angles and form an acute or obtuse arc between them. If you can write it, you can have it.

Find two angles which describe the arc shape. These will be two angles you find by going CW and CCW from the forward direction. The angular sweep amount will be informed by the “percentage” argument. (if 25%, these will be 45 and -45 degrees from the forward direction).

Decide how many total points are involved based on desired point density. This can be accomplished by a verts-per-angle variable; something like 1 vert per 5 or 10 degrees sounds reasonable.

In a loop whose iterations are defined by the desired vertex density, sweep the arc defined by the two angles at whatever radius, putting each discovered point in a collection.

You’ll somehow have to arrive at triangles which create a solid shape; the easiest way would be creating a new triangle (think thin pizza slice) between the circle origin and each two verts you find in “sweep” loop.

It’s going to be a little tricky if you have no prior experience with building meshes or performing this kind of mathematical operation, but it’s definitely do-able. Trial by fire, right?

Unity Mesh API reference