Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I move an object on a random orbital path around a sphere?

I've created some objects at an initial position that is essentially a random point on the sphere offset by some distance (say, 10.0).

Now I want to choose a random direction and have the object orbit the sphere in that direction. How can I accomplish that?

share|improve this question
Are you able to move the object in a non-random direction around the sphere? As in, is the problem selecting a random direction or having the object orbit a sphere? – Byte56 Feb 26 '14 at 17:47
up vote 2 down vote accepted

First generate a random 3D rotation matrix. Then for each frame compute a simple, boring rotation vector around the center (e.g x = r*cos(k*t), y = r*sin(k*t), z = 0), multiply it by the rotation matrix, add it to the center of the sphere, and you have a random orbit.

share|improve this answer
How can I generate a random rotation matrix? Thanks – lacas Mar 11 '14 at 18:22
Create two different, normal, random 3D vectors A and B. Compute C = AxB; C should be perpendicular to the plane defined by A and B. Now compute B' = AxC. A, B' and C should be orthonormal, so you can use them as the columns of a matrix and it will be a rotation matrix. – ggambett Mar 13 '14 at 15:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.