How to write a script to make the sprite scatter into fragments ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hsjaaa

Want to make a defeat animation using script, when the object is defeat, it scatter into fragments and disappear, can I use script to do this?

:bust_in_silhouette: Reply From: markopolo

I don’t know of an easy way to randomly divide a 2d sprite into smaller sprites using a script. However, what you can do is make each fragment its own sprite. During normal animations, the fragment sprites can be hidden. When the defeat happens, hide the overall sprite and show the fragments, then scatter them.

Thanks for your reply, so what I could do is made the pieces and scatter animation at first, when defeat play the animation or I can just move the pieces randomly using script?

hsjaaa | 2019-02-16 11:57

Yep, either way. There’s also the possibility of using a particle system here, or perhaps making the fragments physics objects, etc. lots of different approaches that could work.

markopolo | 2019-02-27 20:40