r/UnityHelp • • Nov 28 '21

Drawing or visualizing geometry

I'm currently working on a personal tool for some geometry maths, but I want to be able to visualize them also. I'm trying to figure the latter, but am having trouble as I've only learned of three ways to draw a line, with a fourth seeming improper (I want to also use days geometry told in production).

I can...

draw gizmos

Debug.drawline (impractical)

(Editor only) Handles class

The fourth being instantiating game objects to render a texture via length over time (l/t).

Is there another way I can accomplish this that permits build or runtime use?

I want to be able to do so for lines, curves, shapes/polygons etc.

I have yet to look into the cs ref for colliders (gizmos) but that's my next step.

My reason is because either I don't understand some relevant workings of Unity APIs (most likely) or they don't exist and I want something I can intelligibly work with.

3 Upvotes

1 comment sorted by

View all comments

1

u/Bonejob Code Guru Nov 28 '21

I ended up buying this;

https://assetstore.unity.com/packages/tools/particles-effects/shapes-173167

doing it in code was a lot of work.

If you want to go down the path of the PolyGon mesh structure. You basically define the mesh using Point coordinates for the shape as vector 2.

var vertices2D = new Vector2[] {
            new Vector2(0,0),
            new Vector2(0,1),
            new Vector2(1,1),
            new Vector2(1,2),
            new Vector2(0,2),
            new Vector2(0,3),
            new Vector2(3,3),
            new Vector2(3,2),
            new Vector2(2,2),
            new Vector2(2,1),
            new Vector2(3,1),
            new Vector2(3,0),
        };

here is a tutorial on the basics.

https://medium.com/@hyperparticle/draw-2d-physics-shapes-in-unity3d-2e0ec634381c