   Move bullet in a sine wave like pattern
  hey, Right now in my game, I have it so i can shoot my weapon toward the mouse cursor, now I want to add a rail gun and have its bullet particles move in a sine wave back and forth along the initial path toward the cursor. How would i take its initial velocity/angle and change every frame it so that it behaves this way?here is what i have so far,Controls are WASD, to thrust up, left/right, and down respectively,Left mouse to fire, and mouse wheel to change weapons http://blackshark.nukelol.com/NSSC/PlovR_001.zipAny help would be much appreciated   
  You don't actually want the *bullet* to move back and forth, do you? I'm assuming that the bullet should actually go straight, and you're just looking for a sine-wavy visual effect...For the visual effect, I imagine an axially-aligned billboard would work (with an appropriate texture or shader applied). If you're not sure how to do this, perhaps you could post back with any specific questions you have.   ;  Do you mean like in C&C tiberian sun where the railgun has that wierd sine-wave trail, or do you mean the bullet actually moves back and forth.If you mean some kind of trail, C&C used a particle system, and jyk has already mentioned another way. Those would be good things to check out.If you actually mean back and forth from initial position to cursor, the bullet's position would be x = x0 + dx*sin(w*t) and likewise for y and z. Where w is the frequency of oscilation in radians per second, t is time, x0 is start position x coordinate, and dx is the difference between start and end. Can't imagine a weapon that would do this though...Please consider that a railgun bullet moves like any other bullet, only faster. So calling it a railgun and then having it do something else might be confusing.   ;  well, the goal is to have the "bullet" be a laser beam made up of hundreds of small particle moving in a sine/wavy visual effect, any particle can do damage to enemies, the beam fades a way pretty fast so collision calculations wouldn't be so bad.what i need help with is taking the bullets/particle velocity, and altering it so it moves in a wave like fashion.   ;Quote:Original post by BlackShark33well, the goal is to have the "bullet" be a laser beam made up of hundreds of small particle moving in a sine/wavy visual effect, any particle can do damage to enemies, the beam fades a way pretty fast so collision calculations wouldn't be so bad.what i need help with is taking the bullets/particle velocity, and altering it so it moves in a wave like fashion.Ok, setting aside any physics-related issues for now...Whether the effect is instantaneous or not, one way or another, you'll most likely need to trace out a series of points along the path of the projectile(s)/particles at some regular interval.The first thing you'll need is a coordinate system (a position and two or three orthogonal basis vectors). The origin is where the effect emanates, and the basis can be derived from the current weapon transform, or by using the 'axial billboarding' technique mentioned earlier (the latter method will ensure that the effect is 'maximally flat' relative to the camera).Say that the basis is set up so that +z is the forward direction vector, and x is to the side. A point corresponding to the parametric value t can be computed as follows (typed into post, so no guarantee of correctness):distance = t * z_distance_per_unit;float theta = t * angle_delta_per_unit;float offset = sin(theta) * effect_amplitude;vector3 p = position + z * distance + x * offset;The parameters 'z_distance_per_unit', 'angle_delta_per_unit', and 'effect_amplitude' can be tweaked to give the path the desired shape.   ;  so what would be a valid value for t? 0 - 1? 1-100?   ;If I understand jyk correctly, t can be in whatever range suitable for the effect. The function simply creates positions on a sine-shaped path, where t is some value to represent how far along the path you are. With all parameters set to 1 it will effectively give you points on a normal sin graph as you increase t, which repeats itself on a 2Pi interval.;Quote:If I understand jyk correctly, t can be in whatever range suitable for the effect. The function simply creates positions on a sine-shaped path, where t is some value to represent how far along the path you are.Right, this is what I had in mind. (@The OP: If the distance you want the projectiles to travel is, say, total_distance, the maximum value for t would be total_distance / z_distance_per_unit.)   