- Home /
Stop a line renderer from rotating when new segments are added?
I have a 2D game with an ortho camera. My issue is that when I try to draw a box using a line renderer, I get something like this:
This image comes from this thread, which discusses a similar issue.
Is there any to prevent the line renderer from rotating as it draws new segments?
If not, what is the best way to draw a box (I actually need a grid, but a box is a decent starting point). Any ideas?
Thanks,
Answer by AlwaysSunny · Apr 30, 2013 at 05:42 PM
If you really need a grid, and it really /needs/ to be made of line renderers, you should probably write a script that will create, place, and re-size a prefab line renderer with the other settings you want. Each line renderer will have just two points, a beginning and end. This way, you can easily control the number of cells and their size, even the line thickness, by changing just a few variables.
If it doesn't have to be line renderers for some other reason, it probably shouldn't be, and should use a semi-transparent grid texture on a plane instead. There are other methods too (for instance, try the Grid Projector in the Projectors folder of Standard Assets by projecting it onto a transparent plane).
To answer your question, the "rotation" you're seeing appears to come from the nature of line renderers - they're not able to draw 90 degree angles (or any non-zero angles, actually) without some distortion. That's just the way they work, since each "face" will attempt to orient itself automatically. If there's a way to change that behavior to force everything to "lie flat", I'm not familiar with it.
I didn't even know a grid projection was a thing, that will work perfectly! If case anyone needs this in the future here is a link on how to make a grid projection.
Thanks AlwaysSunny!
Your answer
![](https://koobas.hobune.stream/wayback/20220613101312im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotating an object in a 3D grid 2 Answers
I'm having trouble with grids and instantiating arrays of prefabs. 1 Answer
How would you add rotation to GridMove.cs from Unify Wiki? 0 Answers
How to create wire in the background and able to move around when rotate the phone 0 Answers
Snapping an object to another 0 Answers