Intro
I was recently asked to produce in 5 days a small prototype of a glass breaking effect. This entailed scripting for mesh transformation and manipulation.The impact force and direction had to influence the effect.I came up with an implementation that is based on calculating the point of impact on the glass surface, and then splitting the original mesh into a number of shard meshes, giving them initial acceleration and letting them go. The physics engine of Unity takes care of the rest.
No particle system was used to produce the shards.
!!! You may grab the Unity Package containing all necessary project files and assets HERE !!!
(The main scene is titled 'MeshCreation' and can be found under the folder AdventuresInUnity)
I will present my implementation in the next series of posts, and then give you a list of ideas and results that others have produced regarding this issue. The distribution of the material covered in each goes like this:
- Part I (this part): Setting up the scene, listing the game objects present
- Part II: Presentation of the scene initialisation, public and private variables
- Part III: Explaining the (rather simple) game mechanics, object interactions and attached scripts
- Part IV: The main course, the particular mesh manipulation approach selected for this project
- Part V: Conclusions, study of other similar approaches, ideas for future implementations and references
The game objects
The concept of the scene is comprised of the following game objects:- a glass surface (a flat mesh), which is a cube scaled down in the y dimension
- little balls that the user releases when clicking the left mouse button, which fall with some force on the glass surface
- a terrain of sorts where the balls fall onto after they break (or fall from) the glass surface. This is in fact another flat mesh.
- a hollow sphere to collect all spheres after falling from the terrain, which destroys them since they are not visible any more from the camera view.
- some lights
Setting the scene
The initial scene includes one (main) camera, one surface, a hollow sphere and 3 directional lights. Their use is as follows:- The camera is the single indispensable object needed in every Unity scene to capture and render the action (see how it is turned 90 deg. around x axis compared to its default rotation, now looking down)
- The terrain, called 'SphereCollector' is there to support the balls after they fall from their collision with the glass surface
- The lights provide some illumination to the scene
- The hollow sphere, called the 'VisibleHorizon' is surrounding all other game objects (not rendered in the picture). I applied a 'flip normals' script on this object at the Start method of the game object class, in order to make it hollow and be able to see inside the other game objects of the scene.
When the scene is started during run-time, some more game objects are created procedurally:
- an object made of glass created out of a simple cube primitive, (on the scene's start)
- balls are generated each time the user releases the left mouse button (after first clicking the button of course).
So the usual order of stationary objects from top to bottom in the y axis are as follows:
- Hollow sphere surrounding the scene (named 'VisibleHorizon')
- Camera
- The 3 directional lights
- Glass surface (named in the scene above as 'GlassTerrain')
- Terrain surface (named in the scene as 'SphereCollector)
More on this follows in the Part II...
Comments