Revolve an object around another object
Hey guys, as the title suggests, basically I have an object in the centre (sun for example) and I want another object to revolve around the first object. How do i accomplish this? Thanks!
Best Answer
-
simo103 Posts: 1,331

Answers
http://dl.dropbox.com/u/8244920/OrbitRotation.zip
1) I decided I would traverse all the positions of a circle around a central point.
2) You can represent the positions of a circle by radian values. So I created an array of 62 elements.
0.0, 0.1, 0.2, etc. to 6.2
Thus I have an array of a complete circle of radian values.
3) Using Vector math and a fixed radius, I calculated the X Position and Y Position of the orbiting Actor/Sprite/Planet using the following math:
Planet_XPOS = Sun_XPOS + (RADIUS * COS(RADIAN_VALUE))
Planet_YPOS = Sun_YPOS + (RADIUS * SIN(RADIAN_VALUE))
4) Note the RADIAN_VALUE is the array I initialized in step 2.
So if you loop through the array from 0 to 62, the Planet will rotate clockwise.
If you go from 62 to 0, it will rotate counter clockwise.
I'm not sure if this helps.