# How to make sparks from two balls colliding

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

## 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 on other sites
I find guessing and trial and error work well.

##### Share on other sites
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 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 on other sites
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 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 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 on other sites
To simulate sparks all you need to do is have lines of varying sizes and shades of a similar color radiating from the point of impact.

##### Share on other sites
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).

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013457
×