• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Rotating a missle around the fighters center

## Recommended Posts

i want to add some missles on my FIghter object. I want to rotate the missle around the Fighters center. I will initilize the pos of the missle to where i want it to be on the fighter. All i want is for the missle to rotate around the objects center , translating will be easy. and when i fire the missle i will initilaze its own local axis. thxs

##### Share on other sites
I think you do circular motion like this (not tested):

  //create this variable outside of the main loopint degrees = 0;////////////////////////////degrees cycles up to 360, then resets to 0degrees += (degrees == 360) ?-360:0;//circle informationint center_x = 300;int center_y = 300;int radius = 10;//ypos will have a max of center_y + 10, min of center_y - 10int ypos = center_y + sin(degrees)*radius//xpos will have a max of center_x + 10, min of center_x - 10int xpos = center_x + cos(degrees)*radius//xpos and ypos give you are your new co-ordinates on the circle to blit to!

##### Share on other sites
its a 3d object and i dont think i understand your code. center is the center of the object that we going to rotate on right?

##### Share on other sites
yeah. It''s more trigonometry - uses the unit circle phenomenon.

Basically, the degree variable counts up from 0 to 360, then at 360 resets to 0. This represents the rotation angle.

Imagine that your rotation angle is a line extending from the centre of the circle, moving along the circumference of the circle. That''s the path you want the missile to take. As the degree changes, the trigonometric functions of cosine and sine change as well.
It would take a couple hours to explain the unit circle, but basically, sin(degrees)*radius returns the y-coordinate for that rotation angle, and will never be further from the circle''s center than the radius length. cos(degrees)*radius returns the x-coordinate for that rotation angle, and also has a maximum distance from the centre of the radius length.

I''m not sure which language you using, but often you''ll need the degree angle in radians. To convert from degrees to radians, multiply the degree number by (pi/180) before you use it in a sin() or cos() function.