- Home /
Draw a line and instantiate it as a game object
I would like to draw a line and then instantiate the drawn line as a game object with a rigidbody2D and polygoncollider2D components(similar as in "Crayon physics" and "Magic Pen"). I'm using the GL.LINES example to draw lines in 2D space but have no idea yet as how to make this drawn lines as objects. Any ideas?
you want to make them a series of mesh squares? like flat thingies? it's a case of writing triangles... 2 triangles is a square, and then you can line squares up with your line... you have to use the mesh class to write a new mesh with vertices and triangles and a uv. its abit advanced. i could do it in 1 day though. perhaps less like 4-5 hours.
What get's drawn on the screen and what exists in RA$$anonymous$$ as "objects", are two very different, incompatible forms of data. What is drawn on the screen is in the form of individual pixels, not associated to any object or entity, while objects in the scene are completely the opposite.
To replicate the behaviour, simply "make" an object that renders the lines directly like you are already. Also note that "line" colliders are not part of the Unity physics system so you won't be able to replicate that behaviour entirely.
I'm also interested on how you solve this, I've struggled for many hours with the concept. I'm new to unity so there is alot that I have to learn.
Your answer
Follow this Question
Related Questions
Allowing User to Draw a Gameobject 0 Answers
[Solved] How to instantiate GameObject with different rigidbody parameters 1 Answer
Combine objects instantiated at runtime 2 Answers
Instantiate as child 3 Answers