Sine and Cosine waves!
Posted: Mon Jul 12, 2010 8:55 pm
Hey everyone, me again And whoooo, look what I made xD (I know the code is sloppy but if you can make it shorter, please do xD all I know is it gets the job done )
This is Sine and Cosine waves, for if you want to make a bullet or an enemy that follows a sine or cosine wave.
Usage:
sinWav(speed, time);
cosWav(speed, time);
Speed is how fast it moves, time is how long it stays going in 1 direction :3
IMPORTANT!!!
You must click "Variabels", then click "Add", and make an actor variable named "a", to prevent glitches
ENJOY !
Video:
Screenshot:
This is Sine and Cosine waves, for if you want to make a bullet or an enemy that follows a sine or cosine wave.
Usage:
sinWav(speed, time);
cosWav(speed, time);
Speed is how fast it moves, time is how long it stays going in 1 direction :3
IMPORTANT!!!
You must click "Variabels", then click "Add", and make an actor variable named "a", to prevent glitches
- Code: Select all
void sinWav(double vel, double heights)
{
a++;
if (a>=heights*2){
a = 0 - (heights / 1.5);
}
if (a<heights/1.5 && yvelocity>-vel)
{
yvelocity-=(vel/2);
}
else if (a>=heights/1.5 && yvelocity<vel)
{
yvelocity+=(vel/2);
}
}
void cosWav(double vel, double heights)
{
a++;
if (a>=heights*2){
a = 0 - (heights / 1.5);
}
if (a<heights/1.5 && xvelocity>-vel)
{
xvelocity-=(vel/2);
}
else if (a>=heights/1.5 && xvelocity<vel)
{
xvelocity+=(vel/2);
}
}
ENJOY !
Video:
Screenshot: