Random 2d particle directions

I’m need to generate random particle directions based upon it’s initial direction moving. Here’s a image of what I mean

42838-randomangles.png

1)Object is falling
2) Object hits floor and I need to get a possible range that particles could fly off.
3) Particles fly off at various angles from the object.

I should add this won’t just be for falling objects but for any object hitting something moving in any direction.

Currently I’m cheating a solution like this…

particle.rigidbody2D.AddForce (Vector3.up * 1200f);
			
			float xDir = Random.Range (1, 100);
			
			if (xDir < 50) {
				xDir -= 50;
			}
			
			xDir = xDir / 100;
			
			xDir *= 10000;
								
			particle.rigidbody2D.AddForce (new Vector2 (xDir, 0f));

Which doesn’t seem to be working very well, there must be a better/easier solution?

Sounds like you don’t really need random directions, you need particles to go in a direction opposite to the normal of whatever your object hit.

So an easy way to do this would be a prefab that has a particlesystem on it that spouts particles ‘forwards’, then instantiate that facing the same direction as your hit normal.

i.e.

GameObject particlesPrefab;

void OnCollisionEnter(Collision col){

 Vector3 normal = col.contacts[0].normal;
 Quaternion rot = Quaternion.LookRotation(normal);
 Vector3 pos = col.contacts[0].point;
 Instantiate(particlesPrefab, pos, rot);
 
}

If I misunterstood, you could also use Random.OnUnitCircle for a random direction on a circle and clamp or map them to be inside a range that works, but I don’t have time to look up how to do thst right now.