PDA

View Full Version : Movement in a Figure-8



C-Dawg
11-18-2006, 01:30 PM
Heya Saffith.

I'd wondered about a mathematics of movement guide awhile ago. Still wondering about that. I'd like an FFC to fly arond in a figure-8. I'll do some research on how to set this up, but I suspect that you already know how to do this more efficently that I'll figure.

Saffith
11-18-2006, 11:09 PM
Ah, yeah. I haven't forgotten that post, I'm just taking forever to respond.

A figure eight's not too hard. If you think about it, it's really the same as movement in an ellipse, except it's twice as fast along one axis. This is pretty much it:

for(int i=0; true; i=(i+1)%360)
{
this->X=xCenter+xRadius*Sin(2*i);
this->Y=yCenter+yRadius*Cos(i);
Waitframe();
}
That's vertical; put the 2*i in the cosine instead of the sine for horizontal. Also, that'll start at the bottom. If you add to i, it'll start elsewhere. So, for example, Sin(2*(i+90)) and Cos(i+90) will start at the center. If you want to adjust the speed, just multiply the numbers passed to Sin and Cos. You may have to change the 360 in that case, though.