Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

Sine wave at an angle?

3 replies · 3,914 views · Started 02 October 2008

At the moment, I have a movement routine for an enemy worked out to follow a straight line between two points, using y = mx +c.

I want to make it also move in a sine wave sort of pattern, but along that line...

I can only think of how to make things move in a sine wave along a horizontal or vertical line though.

Anyone have any ideas as to how I'd go about doing this?

Just think of the wave movement as an offset along a line perpendicular to the direction you're moving. Something like this:


while(true)
{
// Undo previous frame's offset
this->X-=offset*Cos(angle+90);
this->Y-=offset*Sin(angle+90);

// Move along the overall angle
this->X+=speed*Cos(angle);
this->Y+=speed*Sin(angle);

// Find the offset from the straight line
offset=amplitude*Sin(i);

// Offset movement
this->X+=offset*Cos(angle+90);
this->Y+=offset*Sin(angle+90);

i=(i+1)%360;
Waitframe();
}

Oh, I had it moving using y=mx+c to move it along the line, but this uses sine and cosine to do that, doesn't it?

Hrm ok.

EDIT: With a little fiddling, and a complete conversion to radians it now works ^_^
Thanks.