Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Thunder_Hawk

Serpentine motion

This topic is 5243 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a set of particles in a line that are equally spaced and are moving at a constant horizontal velocity. What I would like to do is to have all of the particles essentially retrace the path of the lead particle, which can freely move up and down, creating a sort of dynamic wave. I would think this could be done with an iterative process (as each succeeding particle follows the particle in front of it), but I don''t know how to approach this problem, and most of my attempts have resulted in a perfect line. The only method that I know would work is to record the lead particle''s position over time in an array and interpolate to place the remaining particles, but I''d like to avoid that if I can...Any ideas? ______________________________________________________________ The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ MySite ______________________________________________________________

Share this post


Link to post
Share on other sites
Advertisement
Heres how i did it. It seemed pretty fast to me.

You have the lead-particles position and you have the child-particle positions.

Now for every frame set each particles( except for the leader particle) position to the particle thats before it in the line.

With that all you have to do is update the leader particle and keep switch the positions of the others.

Share this post


Link to post
Share on other sites
An other interesting, and slightly more flexible
solution to your problem might be ''steering''.

Check out the excellent page [url]www.red3d.com/cwr/steer/[/url]
by Craig Reynolds. Especially his article about leader-following,
can probably be adjusted to your case easily.

Good luck!
Tristan

Share this post


Link to post
Share on other sites
quote:
Original post by FlyingDemon
Now for every frame set each particles( except for the leader particle) position to the particle thats before it in the line.

With that all you have to do is update the leader particle and keep switch the positions of the others.



Note - you have to work from the tail end for this to work. I.e. first update the last particle, then the one-from last etc... and only move the head particle at the end. Otherwise you''ll just get them moving all in line (like in your original post).

Share this post


Link to post
Share on other sites
quote:
Original post by MrRowl
quote:
Original post by FlyingDemon
Now for every frame set each particles( except for the leader particle) position to the particle thats before it in the line.

With that all you have to do is update the leader particle and keep switch the positions of the others.



Note - you have to work from the tail end for this to work. I.e. first update the last particle, then the one-from last etc... and only move the head particle at the end. Otherwise you''ll just get them moving all in line (like in your original post).



Actually this is the first thing that I tried. The problem is that you would need an infinite number of particles for the effect to work as I was hoping for (for each x value there is a corresponding y value). In fact, since my lead particle could only have a constant positive or negative vertical velocity, the result was always a line. I also tried allowing the particles to drift until they were a certain distance from the preceding particle and then pulling them along (simulating a string to a limited degree) with some success.

I know that some sort of steering behaviour could have done the trick, but I managed to get the system working beautifully by setting my physics to a constant stepsize and recording the position of the lead particle with a rotating deque. This solution only wastes about a kilobyte of memory, and this is the main effect in my (rather simple) game, so I doubt I should concern myself with a more memory-efficient approach.

Thanks anyway though...

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
If you want no state, then each particle has to take the position of the preceding particle at each step. That''ll look bad.

You need to store, per particle, enough state to record the position the particle was in at time t-dt, where dt is the time between particle emissions. Then, stick the particles in an array, and set each particle''s position to its preceding particles position at t-dt. Last, iterate all particles again and slide their history over. (The last part can be optimized out using rotating/modulo addressing)

An alternative is to describe the positions of the particles using a spline, and just plug in different values for "t" to evaluate where to put the particles, but that won''t work well for dynamically generated trajectories.

Last alternative is to make the particle path be deterministic from the surroundings, and just run the same simulation for each particle, which is expensive.

Share this post


Link to post
Share on other sites
quote:
Original post by hplus0603
If you want no state, then each particle has to take the position of the preceding particle at each step. That''ll look bad.

You need to store, per particle, enough state to record the position the particle was in at time t-dt, where dt is the time between particle emissions. Then, stick the particles in an array, and set each particle''s position to its preceding particles position at t-dt. Last, iterate all particles again and slide their history over. (The last part can be optimized out using rotating/modulo addressing)

An alternative is to describe the positions of the particles using a spline, and just plug in different values for "t" to evaluate where to put the particles, but that won''t work well for dynamically generated trajectories.

Last alternative is to make the particle path be deterministic from the surroundings, and just run the same simulation for each particle, which is expensive.


I guess I should have said that I have a fixed number of particles. With these constraints, it''s only necessary to have a history of the lead particle at a frequency determined by the horizontal speed of the system and the distance between succeeding particles, and even then I''d only need to record the verticle position of the particle due the relative spacing of the x-coordinates. Did I mention that I''m rather happy with the way my solution worked out?

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!