Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cj31387 · Oct 27, 2012 at 09:23 PM · effectpolygonexplode

Explode a Mesh into polygons efffect?

Hi, Does anyone know any way to make a mesh blow up in unity when you hit it and all the polygons from the mesh explode and fly away? For instance say I shoot an enemy fighter, it has 1200 polygons, it dies and I want the whole mesh to break apart 1200 polygons or maybe 2400 tris and fly away then get deleted after a few seconds. Is this possible in unity?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Bunny83 · Oct 27, 2012 at 11:11 PM

So basically you want this, right?

ps: The bullettime effect (timescale) looks a bit strange now since the last engine update. That's because the fixedupdate rate will also be scaled down which results in way less physics frames, which results in a choppy movement.

Here's my old webbuild.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Jessespike · Oct 27, 2012 at 10:49 PM

It is possible. but Unity doesn't have a feature to do this exactly. You would need to create your own method. Perhaps when a enemy fighter dies, the model gets replaced with a cut up version. each piece or gib would have a Rigid body attached, add an explosive force and enjoy.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Piflik · Oct 27, 2012 at 10:58 PM

I faked that effect by simply creating a particle effect with a triangle texture. On death I replace the mesh with that particle effect. But I guess it only works because of the simple graphics style I use...would be difficult with fully textured models...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by kaedmon · Mar 18, 2013 at 09:50 PM

I came across this. It has been tested on iPhone.

 /*
 // DestructibleObject.cs
 //
 // Written by:            Eli (demonpants), modified slightly by Ben
 //
 // Functionality:        Explode apart a mesh into individual GameObjects
 //
 // How it is done:        Add to an object with a mesh renderer.
 //                         It reorganizes the vertices, splitting, and sending along the normal.
 //
 // Prospective Uses:    1. Spin as they move, rather than only moving linearly
 //                         2. Be affected by gravity
 //                         3. Bounce off other objects (with the help of, say, a box collider approximating the shape of the triangle)
 //                         4. Make a sound when they bounce
 //                         5. Cause damage when they hit other game entities
 // 
 // Discussion/Source:    http://forum.unity3d.com/threads/11112-Splitting-a-Mesh
 //
 /////////////////////////*/
 
 //DestructibleObject - provides functionality to destroy whatever GameObject the script is attached to
 //the attached object must have a MeshFilter in its children, and its shrapnel objects must have a renderer in the root.
 //by Eli
  
 using UnityEngine;
 using System.Collections;
  
 public class DestructibleObject : MonoBehaviour
 {
     public GameObject shrapnelPrefab;
     //public AudioClip breakSound;
     public float lifespan = 10.0f;
     public float fadeTime = 0.5f;
    
     protected bool destroyed = false;
     protected float lifetime;
     protected GameObject[] pieces;
    
     public virtual void Update()
     {
         if (destroyed)
         {
             lifetime -= Time.deltaTime;
            
             //out of time, destroy this object
             if (lifetime <= 0.0f)
             {
                 Object.Destroy(gameObject);
             }
             //fade out before destroying
             else if (lifetime <= fadeTime)
             {
                 for (int i = 0; i < pieces.Length; i++)
                 {
                     Color c = pieces[i].renderer.material.color;
                     c.a = 1.0f - ((fadeTime - lifetime) / fadeTime);
                     pieces[i].renderer.material.color = c;
                 }
             }
         }
     }
    
     public virtual void Explode()
     {
         if (destroyed)
         {
             return;
         }
         destroyed = true;
         lifetime = lifespan + fadeTime;
        
         //construct all the individual destructible pieces from our mesh
         MeshFilter filter = GetComponentInChildren(typeof(MeshFilter)) as MeshFilter;
         Mesh mesh = filter.mesh;
         pieces = new GameObject[mesh.triangles.Length/3];
         //a sneaky easy way to get the children to be sized correctly is to have a unit scale when spawning them, then restore it later
         Vector3 oldScale = transform.localScale;
         transform.localScale = new Vector3(1,1,1);
        
         for (int i = 0; i < mesh.triangles.Length; i+=3)
         {   
             GameObject go = GameObject.Instantiate(shrapnelPrefab) as GameObject;
             Mesh newMesh = (go.GetComponent(typeof(MeshFilter)) as MeshFilter).mesh;
             newMesh.vertices    = new Vector3[]
             {
                 mesh.vertices[mesh.triangles[i+0]],
                 mesh.vertices[mesh.triangles[i+1]],
                 mesh.vertices[mesh.triangles[i+2]],
                 mesh.vertices[mesh.triangles[i+0]] - mesh.normals[mesh.triangles[i+0]] * 0.15f, //need to turn this plane 3D
                 mesh.vertices[mesh.triangles[i+1]] - mesh.normals[mesh.triangles[i+1]] * 0.15f,
                 mesh.vertices[mesh.triangles[i+2]] - mesh.normals[mesh.triangles[i+2]] * 0.15f
             };
             newMesh.uv          = new Vector2[]
             {
                 mesh.uv[mesh.triangles[i+0]],
                 mesh.uv[mesh.triangles[i+1]],
                 mesh.uv[mesh.triangles[i+2]],
                 mesh.uv[mesh.triangles[i+0]],
                 mesh.uv[mesh.triangles[i+1]],
                 mesh.uv[mesh.triangles[i+2]]
             };
             newMesh.triangles   = new int[]
             {
                 0, 2, 3,
                 2, 5, 3,
                 0, 3, 1,
                 1, 3, 4,
                 1, 4, 2,
                 2, 4, 5,
                 2, 0, 1,
                 5, 4, 3
             };
             newMesh.RecalculateNormals();
             (go.collider as MeshCollider).sharedMesh = newMesh;
             go.transform.parent = filter.transform;
             go.transform.localPosition = Vector3.zero;
             go.transform.localRotation = Quaternion.identity;
             pieces[i/3] = go;
         }
         mesh.triangles = new int[0];
         mesh.vertices = new Vector3[0];
         mesh.uv = new Vector2[0];
         mesh.normals = new Vector3[0];
         transform.localScale = oldScale;
         Object.Destroy(collider);
         //audio.PlayOneShot(breakSound);
     }
    
     public GameObject[] GetPieces()
     {
         return pieces;
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bullet hit effect take the color of the material color 0 Answers

ui animation effect 0 Answers

Partilcle effect help needed 2 Answers

Shaders: Overwrite something? 1 Answer

How to do this Effect on GameObject like Border light? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges