Creating and exporting destroyable objects

There are several methods of setting up breakable assets that the player can destroy in CryENGINE. In this recipe, we will be going through the creation of a destroyable object.

Destroyable objects are assets that contain the original object and pre-created pieces that spawn when this original object is destroyed. It destroys into the pre-created pieces when taking more damage than the specified "health" property of the entity placed in sandbox as a destructible object.

Good candidates for destroyable objects are glass bottles, explosive barrels, computer monitors, and wooden barrels. Larger objects can also be destroyable, but it will depend mostly on what the game play calls for, such as a destroyable vehicle or wall.

All of these assets normally consist of pre-created pieces that emit when the object is destroyed.

Getting ready

You should have already created a basic object that you will in turn make destructible.

In this recipe, we will use the wooden_barrel_simple asset created in the last recipe.

How to do it...

To create a .CGF containing the object's broken pieces, we must create them as submodels for our main mesh.

Each submodel also must have physics proxy geometry. The submodel's name and its User Defined Properties determine its behavior.

The object must consist of the main original model.

This node or object MUST be named Main that will act as the alive geometry.

Note

Main is the (only) pre-destruction submodel.

We must now create a new mesh that will be the destroyed geometry that will replace the original mesh when the object is destroyed. Essentially this new mesh will act as the dead geometry.

Name this object remain. It will be used as the permanent post-destruction submodel, which replaces Main when the object's state changes from alive to dead.

Note

If no node is named remain then all pieces other than main will be destruction pieces.

This model should consist of different and realistically broken pieces that will be spawned as the destroyable object is destroyed.

Each one of these pieces needs to have a physical proxy.

How to do it...

Before exporting the object, place all objects at origin, so that they are intersecting each other.

The orientation in world coordinates should be 0/0/0 for all the pieces.

Turn OFF Merge All Nodes and click export.

Note

The CGF must be exported with the Merge Multiple Nodes checkbox deselected, to produce multi-piece geometry.

Object can now be placed in Sandbox as a destroyable entity.

By default, the pieces spawn in the position in which they are placed in the CGF, relative to the original model.

How it works...

A destroyable object can be in two distinct states, an "Alive" state or a "Dead" state.

In the "Alive" state, the object acts precisely like you'd expect a normal physical entity to react. It can be set up to be a rigid body or a static physical entity.

After taking more damage than the specified "health", it will go into the Dead state. When going into the Dead state, as a destroyable object entity it can optionally generate a physical explosion and apply area damage on the surrounding entities. It can spawn a particle effect, and finally replace the original geometry of the entity with either destroyed geometry and/or pre-broken pieces of the original geometry. When the object breaks due to a hit from a projectile, this hit impulse is applied to the pieces in addition to any explosion impulse that occurs on the entity.

There's more...

As there can be many different types of breakable assets used within the CryENGINE you will likely want to know more about the different types of destructible and physical reactions you can create for objects.

Two-dimensional breakable assets

Using 2D breakable objects is a useful technique for level objects like glass, ice, wood, or walls. The technique works very well with thin and mostly flat mesh objects. This is controlled through the surface type of an object set in its .MTL file.

Some surface types have been specifically set up for two-dimensional breakage.

Some rules for these objects are that the object must be seven times thinner, in the direction of breaking, more than the length of the other two axes. Each triangle on the object cannot exceed 15degrees deflection between them, so keeping these meshes flat is a good idea.

Jointed breakables

Breakable objects are also sometimes referred to as jointed breakables. These are structures that are built of separate meshes being held together by virtual joints rather than having sub-models spawn. On destruction all the pieces are already rendered.

The parts can be individually disjointed by applying physical force bigger than the joint limits by using things like a gun, or by player interactions such as explosions, and so on.

Some good examples of breakable objects are road signs, wooden fences, or a wooden shack. All these assets are made of parts that are assembled, like in the real world.

Breakable objects are generally placed as brushes or geometry entities. However, you can also place them as BreakableObjects Entity.

For furniture or anything that doesn't require a base attached to the ground that remains after it's broken, it is better to use a rigidbodyEx or a basicEntity. If you need the remaining part to stay static, then it is better to use a breakable object, and specify the mass of the part as 0. If this isn't done, the engine will determine at random which part 'remains' as the static object.

User defined properties

Some parameters can be added to individual objects in a destroyable object asset:

  • generic = count: This causes the piece to be spawned multiple times in random locations, throughout the original model. The count specifies how many times it is spawned. There can be multiple generic pieces.
  • sizevar = var: For generic pieces, this randomizes the size of each piece, by a scale of 1-var to 1+var.
  • entity: If this is set, the piece is spawned as a persistent entity. Otherwise, it is spawned as a particle.
  • density {{density or =mass}} = mass: This overrides either the density or the mass of the piece. Otherwise, it uses the same density as the whole object.

See also

  • Having learned how to use physics and breakables, go to the Chapter 11, Fun Physics to use your destructible objects in unique ways
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.245.167