Sine and Cosine waves!

Talk about making games.

Sine and Cosine waves!

Postby Hblade » Mon Jul 12, 2010 8:55 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Sine and Cosine waves!

Postby BloodRedDragon » Fri Dec 06, 2013 1:51 pm

Does not work. Getting errors.
Current projects:
Techno-Tank Arena: on hold
Techno-Tank SuperPortal (working title): 0.1%
Bowels of Galaxies: 35% (was a bit too optimistic)
User avatar
BloodRedDragon
 
Posts: 123
Joined: Tue Jan 29, 2008 10:07 pm
Location: The Underworld
Score: 5 Give a positive score

Re: Sine and Cosine waves!

Postby lcl » Fri Dec 06, 2013 6:13 pm

You have to put the code to 'Global Code' and then call it from en event of an actor.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron