- Home /
Draw shortest distance between 2 points on a sphere
Hello guys! I'm making a game, but I encountered a problem. That looks easy to fix, but I think it's not. I couldn't fix that, even I waste my 2 days.
I have a sphere, it's classic sphere primitive from the menu. I have created two empty game object and set their parents to my lovely sphere :) I want to draw a line between 2 points. Line renderer works, but it draws straight. I want to draw a circular line between these. How can I do this? I don't have any idea.
I want to draw a line like this(circular)
But line renderer draws like this, and so I can't see the middle of the line, because it's passing in the sphere. (straight)
Answer by Bunny83 · Aug 26, 2018 at 03:36 PM
Well there are several possibilities how you could draw this arc. Since you already use a linerenderer i may suggest using the line renderer. Of course to draw an arc you need several line segments to approximate the arc. Though the line renderer can be used for that.
The easiest solution is to simply use Vector3.Slerp with a relative vector from the sphere center to the first point as start vector and another vector from the center to the end point. When you increase the "t" value of the Slerp you get intermediate point between start and end on the sphere's surface (of course as long as the sphere stays smooth, so no height displacements)
So just set the positionCount to 100 (or whatever you like), create a Vector3 array with that many elements and fill it using Slerp from 0 to 1 in 100 steps. Finally just use SetPositions and pass the array with the points.
Thanks for the detailed answer :) Really good way to do this and it works like a charm :)
I have a new problem, anymore. Can you look https://answers.unity.com/questions/1546512/detect-mouse-click-on-line-renderer.html ? $$anonymous$$aybe you can fix this, too. Because you are really talented :)
Thank you, again.
Your answer
Follow this Question
Related Questions
How to find the radius area of linerencderer drawn circle and move objects inside ? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Serialize a LineRenderer 2 Answers
Drawing line from plane edge 1 Answer