Drawing a "safety zone" around an object

Hi!

So I have an object (placed in origo) and around this object I want to create a colored zone which will illustrate a safety zone (don’t get to close!) but I don’t know the best way to create it. I would like to input coordinates and have the area drawn between these. I guess it’s not a problem if the area is square but what if the area is a triangle or a pentagon?

Does anybody have any suggestions?

Thanks!

If you want so the “safe zone” is in the same geometry It’s mesh is, but bigger. You could dynamically create objects mesh twin only (without colliders) and add transparent dynamic(moving) shader. But for the start you could set just a transparent greenish color, maybe even pulsing.

In order to get the effect shown in the picture, you will need to either procedurally generate meshes or use quads (or planes, if you need lots of triangles).

In case you need the height to be somehow rounded or otherwise non-square, you will need to generate your own meshes. I won’t go deeper, because I’ve never had to create my own meshes procedurally in Unity and don’t really know how. I found this blog that might be of use if you need to go down this road.

The easier case, which you demonstrated in your picture, is to generate a sphere, cylinder or quad(s) (CreatePrimitive) and adjust them appropriately in the 3D world. If you’ve somehow mapped the grid locations to game-world points, then positioning the primitive(s) should be easy.

In order to get the area-feel, you should use a transparent shader+material on each quad. Try to keep the material the same on each quad to allow for batching.

As for how to determine which primitive to do, just count the positions input by the user: 1 point could mean a sphere, two points ‘a wall’ 3 points a triangle etc.