# How to have coins burst out in random directions after destroying an object in unity?

I want coins to burst out of an obstacle in random directions after I destroy it, kind of like the rings in sonic. I have everything else done: the physics, bouncing, instantiating to coins. I just don’t know how to get them to fly out in random directions. Here’s my script:

``````while (counter < 5){
counter++;
Instantiate(token, transform.position, transform.rotation);
}
Destroy (gameObject, 0.4f);
``````

Any help at all is appreciated!

Break it down, the same as everything else.

Look up how to set movement direction. `rigidbody.velocity=new Vector3(5,3,0);` will shove you right and up. Can use AddForce, but velocity is simpler (and AddForce is just a fancy way to set velocity anyway.)

The x,y,z parts of velocity are just numbers, so look up how to roll random numbers.

But the particle system may work better for you (never tried that version.) For example, if you roll x and z speed both from -5 to 5, you get “all directions” but some have speeds of 0 and just sit there. The real reason to roll dice yourself is that you know the math well (angles, probability curves,) and want to fine-tune it better.