   simple curve equation i guess
  Well i dont wanna do anything special just a curvy line for a particle beam.Like this line,Ive done a simple circle with sin and cos x, y between angles 0 - 360 im guessing a line like that is something similar ?Im just after nice simple lines that look good for weapon paths instead of boring straight lines.I suck at maths so i dont really know where to begin with this so any help be appreciated.Reason im after this is because im implementing some weapons for a side scrolling shooter id like to have more than just straight line based weapons. All the weapons are particle based so the particles would either spawn at a random point on the line or trace the line along depending how old the given particle is.thx for any help.   
  All you need for this is the sine function. The code should be easy to sketch out and I'd be happy to do it, but first, do you need only axis-aligned beams (i.e. vertical or horizontal), or arbitrarily oriented (pointing in any direction)? If the former, just horizontal, just vertical, or both?   ;Quote:Original post by fishleg003Well i dont wanna do anything special just a curvy line for a particle beam...actually that specific curve might be a problem to replicate [grin]   ;Quote:Original post by DayZeroQuote:Original post by fishleg003Well i dont wanna do anything special just a curvy line for a particle beam...actually that specific curve might be a problem to replicate [grin]Yeah, I'm not sure what that function is :-) But, for horizontal sine-wave beams, how about something like the following:void DrawBeam(    float x1, // Beam start x position    float x2, // Beam end x position    float y,  // Beam y position    float width,   // How wide you want the beam to be    int numOscillations,// How many oscillations you want    int stepsPerOscillation) // How many line segments to draw per oscillation{    int totalSteps = numOscillations*stepsPerOscillation;    float xDelta = (x2-x1)/(float)totalSteps;    float angleDelta = TWO_PI/(float)stepsPerOscillation; // You have to supply TWO_PI    glBegin(GL_LINE_STRIP);    for (int i = 0; i <= totalSteps; ++i) {   glVertex2f(x1+(float)i*xDelta,y+sin((float)i*angleDelta)*width*0.5f);    }    glEnd();}I'm not sure if I got all that right, but you might try it and see what happens.   ;  Something like this for 2d space where theta is the angle of your trajectory, x is the current distance from the gun and xstart/ystart is the position you want to start your bullet at and frequency is how quick you want the repeat to be and height is how tall up and down you want the bullet to wave:for(int x = 0;x<bulletDistance && !collision(x);x++){   y = sin((x*frequency))*height;   x2 = (cos(theta)*x - sin(theta)*y) + xstart;   y2 = (sin(theta)*x + cos(theta)*y) + ystart;   drawBullet(x2, y2);}basically, you draw (x2, y2) as the bullet and you increase x through a loop.Obviously you can't run a loop -exactly- like this or it'll stop the rest of your game while your bullets just magically stop time and complete themselves, but you get the picture. You'll need to call some sort of bullet update function from your main loop.This isn't terribly efficient, I'm sure there's a better way of going about this than rotating the point based on the angle, somehow build the rotation angle into the line equation perhapse?  I'm too math dumb to do it properly though and this is probably fast enough for what you need.(for extra fun you can run a second line in parallel in the form of y = cos(x*frequency+1.5)*height which will run opposite your sin equation making for converging waves.)[Edited by - M2tM on December 6, 2005 5:15:31 PM];  wow fast replies no dammit i want that exact line lol :PI like the idea of having two of them crossing each other would look pritty cool ghostbuster style.So for me ill be using time so let see if ive got this right,Im not totally sure if this is correct but,1, id work out a value between 0 - 1 given time bullet was fired the duration that bullet is alive for and the current time.2, times this by the length of my line would give me a point between the start and end point relative to the current time?void Update_BulletPos(OldBullet_Pos, Current_time){y = sin((OldBullet_Pos.x*frequency))*height;length = line.end - line.start;distance = (Current_time - Time_Fired) / (Bullet_Duration);distance = distance * length;NewBulletpos.x = (cos(theta)*distance - sin(theta)*y) + xstart;NewBulletpos.y = (sin(theta)*distance + cos(theta)*y) + ystart;return NewBulletpos;}thx again   ;bool Update_BulletPos(Bullet& currentBullet, float currentTime){   if((currentBullet.duration+currentBullet.timeFired) < currentTime)   { return 0;  //returns 0 to indicate the bullet has petered out   }   float distance = (currentTime - currentBullet.timeFired) / (currentBullet.duration);   distance = distance * currentBullet.rangeOfBullet;   int y = sin((currentBullet.xstart+distance)*currentBullet.frequency)*currentBullet.height;   currentBullet.y = (sin(currentBullet.angle)*(currentBullet.xstart+(int)distance) + cos(currentBullet.angle)*y);   currentBullet.x = (cos(currentBullet.angle)*(currentBullet.xstart+(int)distance) - sin(currentBullet.angle)*y);   //note: you draw x as (currentBullet.x+currentBullet.xstart)   //and draw y as (currentBullet.y+currentBullet.ystart)   return 1;}Something like this?  When the bullet is initially fired-it has a timestamp called bullet::timeFired-it gets another time called bullet::duration which indicates how long the bullet is live for.-it gets a bullet::rangeOfBullet int assigned to it (which is pixels it shoots in total over the given duration)-it gets an angle to be fired along... remember this angle is in radians, not degrees.... To change radians to degrees: ( degrees = radians * (180/pi) )  to change degrees to radians: ( radians = degrees * (pi/180) )-it gets an xstart and ystart value which is the initial position in your world which it starts at...  Don't forget if you have the world scrolling that you'll need to take this into account with your bullets and everything else.-it gets a frequency and a height.  if height is 0 then you get a straight line which means that you can use this same algorithm and bullet setup for straight shooting bullets too.*edit: Take heed of my note, I made a mistake and fixed it.  If you store xstart and ystart in the x and y positions of your bullets then it will add an extra velocity to your bullet which was not intended.  the code should be correct now but call me on anything that looks wrong because I just did this quick.[Edited by - M2tM on December 6, 2005 8:12:33 PM]