- Home /
Question by
udk_lethal_d0se · Sep 29, 2016 at 07:04 PM ·
c#spherenormalsarc
How to calculate the surface normal Vector3 between two Vector3's on a Sphere.
Hi all,
I'm currently placing objects on the surface of a sphere, and can already calculate the point between the two object positions (using the code below). I have a Line Renderer drawing a line from point A to C, with the calculated point being B, however, how can I calculate the surface normal position of point B so my line will arc across the sphere?
public static void CreateLink(GameObject linkModeTarget)
{
Vector3 pos = Vector3.Lerp(linkModeParent.transform.GetChild(0).position, linkModeTarget.transform.GetChild(0).position, 0.5f);
LineRenderer linkModePrefabOptions = linkModePrefab.transform.GetChild(0).GetComponent<LineRenderer>();
linkModePrefabOptions.SetPosition(0, linkModeParent.transform.GetChild(0).position);
linkModePrefabOptions.SetPosition(1, pos);
linkModePrefabOptions.SetPosition(2, linkModeTarget.transform.GetChild(0).position);
}
This is the current result:
And this is what I'm after:
Thanks for having a look.
sphere-current.jpg
(24.8 kB)
sphere-desired.jpg
(19.9 kB)
Comment
Best Answer
Answer by flaviusxvii · Sep 29, 2016 at 09:44 PM
Let SC be the center of the sphere.
Let BB be 'bad B', the B you currently have.
Let R be the radius of the sphere
B = SC + ((BB - SC).normalized * R)
Excellent, works wonderfully. Thank you very much.
No problem. Good luck with your project.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093715im_/https://answers.unity.com/themes/thub/images/avi.jpg)