• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Avanak · Mar 17, 2015 at 03:41 PM · camerascalelinerendererzoomspace

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · Mar 17, 2015 at 03:12 PM 0
Share

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(min, 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. ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image echl · May 16, 2016 at 10:50 PM 1
Share

How did you use the above line of code?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there a way to zoom GUI and scene at the same time? 0 Answers

Accurate Pinch Zoom 1 Answer

Need help with 2D orthographic camera zooming 2 Answers

Avoid changing the object's scales 0 Answers

How to do perspective camera zoom? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges