Search Unity

How to destroy mesh of an object into pieces on Mouse click like it happen in SuperHot....

Discussion in 'Scripting' started by Pulkitguglani1011, Dec 2, 2019.

  1. Pulkitguglani1011

    Pulkitguglani1011

    Joined:
    Nov 24, 2018
    Posts:
    9
    In SuperHot game when bullet hits the enemy , enemy's mesh is being destroyed from that part only like a glass ornament is being hitted by a bullet.
    How to achieve it in Unity?
    What I want is if bullet hit head only head should be destroyed in pieces.....
    Also I don't want to prebuild the small pieces and then adding a force to move them away from their parents , I want all of this at Runtime with a single mesh object.
    Any suggestion?
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,741
    Yes indeed! First step: get familiar with procedural geometry creation in Unity3D.

    Procedural geometry in Unity3D is very straightforward, probably one of the simplest places to grasp it.

    That said, there is still a fair amount of domain knowledge to grasp before you're fully at home with it.

    To aid your learning, there are tons of procgen resources out there for Unity3D, and I have made my own called MAKEGEO.

    For the specific problem you cite, there is also the issue of reconfiguring the ragdoll physics so that the different chunks you pull apart continue to behave like pieces of meat, rather than becoming brittle.

    For the first pass at this problem, I recommend shattering the enemy into its respective chunks and putting each one on a GameObject and sending it off with its own trajectory. That gets you out of fiddling with ragdoll stuff early on, and you can go back and add that in later.

    My MakeGeo project is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
    Pulkitguglani1011 and ADNCG like this.
  3. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    There are several ways to do it-
    1. One way is to use particles. Write a script that deletes/deactivates the original object and spawns a particle effect. Have the particle effect emit particles that look like pieces of the original object. You can enable physics to have them bounce off of things, but let them quickly disappear.
    2. Another way is to actually create pieces of the object in a 3D modelling program. Many of the major modelling packages include a "fracturing" feature or plug-in. It will let you take a complete model and generate fractured pieces. Import the pieces into unity and add rigidbody/colliders to each one. Create a prefab that's just an empty game object with all of the pieces as children (arranged to look like the original object). Write a script to delete/deactivate the original object and instantiate the prefab in it's place.
    3. It's hypothetically possible to write your own routine to do dynamic fracturing. I think that's what Kurt-Dekker was hinting at.
    4. There are several "fracturing" solutions on the asset store but caveat emptor.
     
    Pulkitguglani1011 likes this.
  4. Pulkitguglani1011

    Pulkitguglani1011

    Joined:
    Nov 24, 2018
    Posts:
    9
    Yes @kdgalla, I am aware of Fracturing ... it is available in Blender and easy to use, but I need Dynamic method so that I don't need to make a different fractured object for each gameObject.... but I like your idea of using Particle effect... it's an easy and fast way to implement it...
    Thanks for the suggestions
     
  5. Pulkitguglani1011

    Pulkitguglani1011

    Joined:
    Nov 24, 2018
    Posts:
    9
    Thanks, I got the idea, going to learn Procedural Mesh Generation now .
    And also I checked your repo on GitHub, hopefully, I will also be able to make those procedural terrains and other stuff soon.
     
    Last edited: Dec 3, 2019