Jump to content
  • Advertisement
Sign in to follow this  
kzar

How to make sparks from two balls colliding

This topic is 4655 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 want to make sparks fly out when two balls crash into each other in my game. Hopefully looking somthing like this: I can figure out the spot the two balls touch and I know how to create particles with movement vectors. What I want to figure out is how I can calculate what velocitys to give the particles so it looks like the sparks are flying away from the crash. Also I'm not sure if the balls radius's effect the calculation but in my game its possible that there could be different size balls. Does anyone know how I would go about this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
A physically correct representation would be unnecessarily complex. Just set the initial velocity of the particles to the relative speed between the balls, multiplied by some constant. Tweak the constant until it looks good.

Share this post


Link to post
Share on other sites
I'm not totaly sure but I think I need to figure out the angle particles can go in, then figure out a normalised random velocity which makes it go in that angle, times that by a random(ish) magnitude and then flip a coin to decide if I should times the whole thing by -1 or not.

If that sounds about right could you explain how I would figure out the angle and then how I would get a random velocity thats traveling within it?

Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The direction of the sparks is perpendicular to the collision. You'd also vary the angle by some small random amount to get them to go in different directions. For the random velocity just try different things until it looks good.

Share this post


Link to post
Share on other sites
Yea, say if I have the angle and I know it faces at a right angle away from the point they hit, how do I calculate a random x and y velocity that makes the particle fly within that angle? Thanks

Share this post


Link to post
Share on other sites
"x,y" :
Is it 2D or 3D? in 2D it is simpler.
General idea, what AP told about: compute collision normal (difference of positions of spheres, normalized), then compute random vector orthogonal to this normal (in 2d there's two such vectors, normal.y,-normal.x and -normal.y,normal.x . One is negative of other. If you are working with 3D, just ask).
That gives you velocity for zero angle of spreading. Add to it normal*random(-alpha,alpha) where alpha is roughly equal to angle of spreading you want, for small angles.

You may want to multiply result by something to control overall speed of particle.
There's some other ways of doing it, of course.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In 2d, an angle represents a direction. The same direction can be represented as a unit vector. For a given angle theta, the corresponding unit vector has x=cos(theta) and y=sin(theta).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!