Advertisement

Ballistic particle system

Started by April 14, 2003 02:31 PM
1 comment, last by KalvinB 21 years, 10 months ago
Using and heavily modifying NeHe's particle system example to allow for a time duration, direction (calculated from starting and destination points) and spread in the X,Y plane I've got the basis for some really nifty effects. However the basic Particle System class allows for movement in all three direction and effects based on gravity. I now want to add a method to define a system of ballistic particles aimed from a starting point to an ending point with a spread in the launch angle and launch direction to effectivly spray the destination point. Z is in and out of the screen, X is left and right and Y is up and down for my calculations. It's a top down view which is why it's set up the way it is. Phi is the angle between the starting(A) and destination(B) point on the XY plane. Theta is the launch angle. V is the launch velocity. Tmax is the time I want it to take to get to from point A to B. g is gravity. I'm starting with the assumption Z = V*sin(theta)*t-g*t^2 Y = V*cos(theta)*sin(phi)*t X = V*cos(theta)*cos(phi)*t solving for when (Y^2+X^2)^(1/2) = distance from A to B I get dist /(cos(theta)*Tmax) = V which is pretty much what I'm looking for as I can spread theta from say 30-60 degrees and V is calculated accordingly to hit point B in Tmax time. Then I can just spread phi and dist a bit to get a spread in the XY plane. However, shouldn't gravity play a role in that equation? The particle needs to get to B from A in Tmax time and Z needs to hit 0 at that time as well. I suppose I could solve the Z equation for g using the results from the V equation but I'd rather keep it a fixed value per system. Ben [edited by - KalvinB on April 14, 2003 3:34:07 PM]
Figured it out.

Z should be - 1/2*g*t^2

Breaking V into Vz and Vxy

Vz = g * Tmax / (2*sin(theta))
Vxy = dist / Tmax

Z = Vz * sin(theta) * t - 1/2 * g * t^2
X = Vxy * cos(phi) * t
Y = Vxy * sin(phi) * t

You can then add a random spread to theta, phi, Tmax and dist to pepper the destination with particles instead of getting a steady stream in one exact spot in even intervals.

If you want to rotate say an arrow you use

arctan [ (Zcur-Zprev)/((Zcur-Zprev)^2+(Tcur-Tprev)^2)^0.5 ]

to get the angle to rotate around the x axis and use phi to rotate around the z axis. You can then rotate the y axis back and forth to get a rocking motion.

Ben

[edited by - KalvinB on April 14, 2003 6:24:49 PM]
Advertisement
Here's a couple screens of the results. I'll post the source for the particle system later at www.icarusindie.com in the DevZone. Click images for larger version.

XY only




Ballistic




Ben

[edited by - KalvinB on April 15, 2003 1:19:26 AM]

This topic is closed to new replies.

Advertisement