Some ways unity achieves the effect of breaking objects-drizzle

Source: Internet
Author: User

The game is getting closer to the reality of the feeling, if there is a really virtual reality device, maybe we will really feel in the real world. The realism of a scene is the result of rendering effects, character AI, game logic, physical effects, and so on. Now the game is getting bigger, besides rendering, physical estimation is part of the best performance. In action games, the destruction of objects and crushing effect, so that the fight more realistic and hearty feeling, this article mainly from their own application of the angle of simple introduction of the impact of the broken effect.

1 Simple implementation

Using the Maya and other tools to make pieces of the object, the game when the object is broken, the first destruction of the original object, and then replaced with fragments of the pretab, the effect is that each fragment of the different afterburner, need to be adjusted to achieve. Refer to: http://www.cnblogs.com/zsb517/p/3986278.html

Notice the use of several functions:

Rigidbody.addexplosionforce: Add explosive force, decrease the force size by distance

Physics.overlapsphere: List of colliding bodies within the detection range

The following code tests the effect:

void Fixedupdate ()

{

if (Input.getkeydown (keycode.space))

{

Raycasthit hit;

if (Physics.raycast (Camera.mainCamera.ScreenPointToRay (input.mouseposition), out hit))

{

Debug.Log ("Addexplosionforce");

Collider[] Hits;

hits = Physics.overlapsphere (Hit.point,raduis);

foreach (Collider t in hits)

{

if (t! = null && t.attachedrigidbody!=null)

T.attachedrigidbody.addexplosionforce (force,t.attachedrigidbody.position,raduis,ups);

T.attachedrigidbody.addforce (New Vector3 (0f,0f,1f) * 500.0f);

}

}

} Split

}

2 Mesh real-time segmentation

The use of plug-in shatter Toolkit 1.41, to achieve similar cut fruit in the effect, can be point-centric to the object divided into several parts or directly using the plane to the object segmentation, this method requires CPU computing function, cutting first according to the plane equation to divide the object into the upper two parts, The triangular patches on the boundary line need to calculate the interpolation of vertices, normals, textures, colors, tangents, etc., and generate new information. Plug-ins implement the basic requirements, but if you achieve individual results, you need to process and extend the events before and after cutting.

Instructions for use:

When you need to break or split an object. You need to attach a Shattertool script instance object and an Uvmap instance object to the object, and after cutting, the fragment of the object will be instantiated as the clone of the original object.

Fragmentation tool scripts require objects This province contains Meshfilter components, Meshcollider and rigidbody components are also required

Note Point 1: If you are using meshcollision and rigid body components, you need to turn on the meshcollider convex option to avoid the quality update of components after splitting

NOTE 2: If the Shattertool.fillcut option is turned on, each edge of the grid belongs to two triangular patches, which means that the grid is closed

About using:

1 attachment shatteroncollision script to object, triggering by triggering a collision

2 Attachment mouse events to objects, including click, Swipe, and drag

3 sends a world coordinate point with "shatter", divided position, triggering the shatter event in the Shattle tool

4 sends a "SPLIT" message with a sequence of polygons in a world coordinate system. Triggering the split event in the Shattle tool

5 using the Shatterscheduler event management mechanism to send messages by adding a task, you can control more events at the root

About the mouse:

1 Crushing effect after mouse click

2 mouse scribing Mode cutting

3 Mouse Drag effect

About hierarchies:

Hierarchyhandler scripts can help achieve chromatography management in cutting

About the effect:

Not too much processing, can be processed by the message event before and after cutting, similar to the management method of Hierarchyhandler, to deal with the effect before and after cutting

Technical implementation:

(1) Calculating facets

Plane Splitplane = new Plane (vector3.normalize (Vector3.cross (line, ray.direction)), hit.point);

Line is a linear vector in the world coordinate system--vector3 lines = Maincamera.screentoworldpoint (new Vector3 (End.X, End.y, near))- Maincamera.screentoworldpoint (New Vector3 (Start.x, Start.y, near));

Ray.direction is the vector of the screen to the cutting point-ray Ray = Maincamera.screenpointtoray (Vector3.lerp (Start, end, (float) i/raycastcount));

The result of the above two forks is that the normal vector of the plane is required, and the cutting pad can be used to determine the cutting plane.

(2) Single point cutting scheme:

Using vectors to generate several random faces, combined with cutting points to form several planes

Similar Unity plugin: Shatter Toolkit 1.41,: http://www.unitymanual.com/thread-19781-1-1.html

3 Blasting effect (fracture maximum of 50 blocks)

Using plug-ins: fracturing__destruction_1.11, the plugin is slightly more complicated, in fact, the basic principle and the first similar, the place is not to take part in the break of art, the plug-in will first break the object according to your settings, create another pile of pieces, And the connection between the pieces of records to facilitate the subsequent implementation of the processing of fragmentation. The completion of the plug-in is very good, basically can be like using particles together, through the settings can achieve some good crushing effect. Because you do not need real-time computing fragmentation, the effects in use are still possible, if you need to prefab, you need to occupy a bit of resources. Please read the Setup Panel carefully before use ~ ~ There are too many parameters. The specific use can refer to here

4 Particle effects

Summary, the host performance is not good, especially the GPU performance is not strong, the two methods produced by the above-mentioned pieces are rigid body nature, the blasting process will be to use the physical engine, so the performance of the cost is more severe, especially in the case of more fragments. Proper control of the number of fragments will be better.

A good effect should be a combination of multiple effects, such as a particle effect immediately after crushing, but the need to feel natural and, of course, also requires good machine performance to support these large amounts of physical computing and rendering. The company's host performance is still relatively poor, too much physical computing and fine rendering will result in Kaka. But honestly, a good game doesn't have to be a very good visual.

Some ways unity achieves the effect of breaking objects-drizzle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.