- Home /
Keep line renderer width same on screen no matter camera distance
So I am displaying a solar system in a scene. The star is in the middle and planets at different distances around it. I have a line renderer component on each planet that creates a circular line around the star to the distance of the planets. I have the line width set so that it looks right when I am zoomed in to the planet. However when I zoom out to view the whole system, the lines are too thin and seem jagged.
Does anyone know a trick to scale the line renderer's width equally to the camera's distance?
I assume you really do mean "line renderer" when you say "line renderer" - I'm not sure you could do this with a trail renderer.
I don't think there's an "easy" mathematical trick, unless your camera movements are going to be very limited. You might consider scaling the width based on the camera's distance from the scene origin (the sun?). Depending on how your camera can move, this may satisfy the request.
scale = $$anonymous$$athf.Lerp($$anonymous$$, max, distanceBetweenCameraAndOrigin / maximumDistanceConsidered);
To achieve truly perspective-independent width, you'll need to programmatically create your lines from multiple dynamically-billboarded quad segments and size them in a way that respects each vertex's position in screen space. This is not something I've ever had to do, but I've done some work in the general area; it's not for the faint of heart. ;)
Answer by Avanak · Mar 18, 2015 at 02:57 PM
Thank you very much AlwaysSunny!
It turned out that this simple script worked just fine:
Vector3.Distance(planetPosition, cameraPosition) / 1000;
Still thanks for the input.
Your answer
Follow this Question
Related Questions
Change UI scale in relation to 3D camera 0 Answers
Is there a way to zoom GUI and scene at the same time? 0 Answers
Stop main camera from zooming 2D 1 Answer
Accurate Pinch Zoom 1 Answer