Page 1 of 1

Sine and Cosine waves!

PostPosted: Mon Jul 12, 2010 8:55 pm
by Hblade
Hey everyone, me again :D 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 :P)

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 :D!

Video:


Screenshot:
function_scrn.JPG

Re: Sine and Cosine waves!

PostPosted: Fri Dec 06, 2013 1:51 pm
by BloodRedDragon
Does not work. Getting errors.

Re: Sine and Cosine waves!

PostPosted: Fri Dec 06, 2013 6:13 pm
by lcl
You have to put the code to 'Global Code' and then call it from en event of an actor.