How to move a line of sprites in a sine wave?

Posted by electroflame on Game Development See other posts from Game Development or by electroflame
Published on 2012-03-29T02:00:03Z Indexed on 2012/03/29 5:42 UTC
Read the original article Hit count: 270

Filed under:
|

So, I'm spawning a horizontal line of enemies that I would like to have move in a nice wave. Currently I tried:

 Enemy.position.X += Enemy.velocity.X;
 Enemy.position.Y += -(float)Math.Cos(Enemy.position.X / 200) * 5;

This...kind of works. But the wave is not a true wave. The top and bottom of one pass are not the same (e.g. 5 for the top, and -5 for the bottom (I don't mean literal points, I just meant that it's not symmetrical)).

Is there a better way to do this? I would like the whole line to move in a wave, so it looks fluid. By that, I mean that it should look like each enemy is "following" the one in front of it. The code I posted does have this fluidity to it, but like I said, it's not a perfect wave.

Any ideas?

Thanks in advance.

© Game Development or respective owner

Related posts about XNA

Related posts about 2d