Jump to content
  • Advertisement
Sign in to follow this  
Jacob_

2D particle system--bouncing effect?

This topic is 3273 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 simple 2D particle-based game using vectors where each particle is a pixel on the screen, and is affected by gravity. What do I need to do to make the particles bounce realistically off other particles or the boundaries of the game window? I already have all the vectors/collisions/piling up stuff coded, just need to know how to do bouncing. This is in Java, but a general explanation of how to do it would be fine too.

Share this post


Link to post
Share on other sites
Advertisement
Hi Jacob_,

particle systems usually do not let particles collide with each other and this also makes things a bit more complicated. If a particle should bounce off a line (e.g. the border of your window) you first have to calculate whether the particle actually reaches the line within the timestep T. If it does you first have to calculate:
1. T_c the time the collision occures (note: T_c must be smaller than T)
2. P_c the point of collision (2d point)
3. V_c the new velocity which is mirrored at the line (2d vector)
The new position is then P_c + (T - T_c)*V_c.

Does that help?

Cheers,
fng

Share this post


Link to post
Share on other sites
"V_c the new velocity which is mirrored at the line (2d vector)"

That's the part I'm having trouble with. What's the best way to find the new vector?

Edit: I could probably do it with a bunch of if/else if statements based on whether the x/y velocities of the current particle are positive or negative, but there has to be a better way.

Share this post


Link to post
Share on other sites
Here the steps to calculate the velocity a general line that is not the window border:
Assuming D is a normal vector along the line that you are colliding with. Then you have to calculate the tangential and normal component V_t and V_n of your original velocity V_o. The tangential component goes parrallel to your line and the normal component is perpendicular to that.

We have:

V_t = (V_o . D) * D
V_n = V_o - V_t

(where A . B denotes the scalar product of two vectors A.x * B.x + A.y * B.y )

The new velocity is then: V_c = - V_o + 2 * V_t

Some nice tutorials concernind 2d collision detection and response can be found here: http://www.metanetsoftware.com/technique.html

Cheers,
fng

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!