Some time ago, I was trying to move a camera (in 3D space) around the player, which ultimately is about moving an object around a sphere.

Now, the equation for the position around a circle is pretty easy and is:

However, I needed equations to find the position over a sphere.

A POINT IN 3D SPACE, DEFINED BY TWO ANGLES AND A DISTANCE FROM THE ORIGIN.

After some research with Google, I came with this solution:

While writting this post, I payed a quick visit to this article in Wikipedia and, according to them, these are the formulas:

 Observations:

  • angleInX is the angle around the X axis.
  • angleInY is the angle around the Y axis.
  • sphereCenter that has at least 3 elements and defines the position of the object we will be moving around. And so, theVector.x is the x attribute of the vector theVector, for example.

I needed to change the formulas from Wikipedia, as they work with the Z-axis as the “upward” axis, while I use the Y-axis instead.

I hope this will be handy to anyone trying to figure out how to move over a sphere.

Share.

About Author

½ computer engineer + ½ videogame developer + ½ gamer. I eat my pizzas 8-bits at a time and develop games for a living.

Leave A Reply