Time for action - making your object destructible

In this example, we will use the wooden_barrel_simple asset created earlier in the chapter. Alternatively, you can open the example file objectswooden_props wooden_barrell_destructible.max.

To create a .cgf containing the object's broken pieces, we must create them as submodels for our main mesh. Each submodel must also have a physics proxy geometry. The submodel's name and User Defined Properties will determine its behavior.

  1. Create the original model to be used as the non-destroyed mesh. In this example, it is the unbroken barrel.
  2. Name the non-destroyed mesh main. It will act as the alive geometry for the entity within CryENGINE.
  3. At this point, you can use various methods within 3ds Max to break up an object. For this example, you can simply cut out the shape using the cut tool within 3ds Max.
  4. First, create the destroyed geometry that will replace the original geometry when the object is destroyed and name this object remain.

    The remain model will be used as the permanent, post-destruction submodel, which replaces main when the destroyable object's entity state changes from alive to dead. You could also add a new, destroyed submaterial and assign it to this mesh as a destroyed texture may appear drastically different.

    If no node is named remain, then all the pieces other than main will be destruction pieces, which are physically dynamic.

  5. Create different and relatively realistically broken pieces, which will be spawned as the destroyable object is destroyed within the CryENIGNE. Name them broken_piece_1 and broken_piece_2, as seen in the following screenshot. If you want to create more pieces, you can simply increment the numbers to broken_piece_3 and so on, depending on how many unique pieces you want created.
  6. Create a physics proxy for each one of these pieces.
    Time for action - making your object destructible
  7. Before exporting the main object, move all the objects to the origin so that they are intersecting each other.
  8. Set the Pivot orientation, if not already set, in world coordinates, to 0,0,0 for all the pieces.
  9. Link all the objects to a 3ds Max Helper named wooden_barrel_breakable, as seen in the following screenshot:
    Time for action - making your object destructible
  10. Uncheck the Merge All Nodes option and click on Export Nodes, as seen in the following screenshot:
    Time for action - making your object destructible

    Note

    The CGF must be exported, with the Merge All Nodes checkbox deselected, to produce multipiece geometry.

  11. Now, we can place the object as a destroyable entity found under the Physics subfolder of the Entity browser in the RollupBar tab, as seen in the following screenshot:
    Time for action - making your object destructible
  12. Set the parameters for the DestroyableObject as follows:
    • Set MaxHealth to a relatively low value of 200
    • Set the Mass to 50
    • Finally, set Invulnerable to False by deselecting the checkbox, as seen in the following screenshot:
    Time for action - making your object destructible
  13. Switch to game mode, and shoot or otherwise damage the object.

    Note that, when the object is destroyed, the pieces spawn in the position in which they were placed in the CGF, relative to the original model, and can be physically simulated as seen in the following screenshot:

    Time for action - making your object destructible

What just happened?

You can use this destructible object for many different functions now as it has two different physical 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 static physical entity. Some fun examples are cliffs, platforms that the character might walk on, bridges, buildings, and so on.

After taking more damage than the specified Maxhealth, the entity will go into the dead state. When going into the dead state, a destroyable object entity can optionally generate a physical explosion and apply area damage to the surrounding entities. It can spawn a particle effect, and finally replace the original geometry of the entity with either the destroyed geometry and/or prebroken 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.

Have a go hero - use some of the other breakability types

There are a few different types of destructibility available in the CryENGINE. Try using some of the other types of destructible objects available.

Specifying physics and render dynamics with user defined properties

Similar to static and simple objects, some parameters can be added to the individual objects in a destroyable object asset. Try adding some of the following User Defined Properties to the pieces from the preceding example:

  1. 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 has been spawned. There can be multiple, generic pieces.
  2. sizevar = var: For generic pieces, this randomizes the size of each piece from a scale of 1-var to 1+var.
  3. entity: If this is set, the piece is spawned as a persistent entity. Otherwise, it is spawned as a particle.
  4. 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.

Breaking two-dimensional assets

Using 2D, breakable objects is a useful technique for level objects, such as glass, ice, wood, or walls, which typically don't have a lot of volume or thickness. The technique works very well with thin and mostly flat mesh objects.

Two-dimensional breakables are 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 already within the CryENGINE Free SDK. Some of these are mat_glass, mat_glass_breakable_safetyglass_large,and mat_glass_breakable_thin_large. Some rules for objects using these surface types are as follows:

  • The object must be seven times thinner, in the direction of breaking, than the length of the other two axes.
  • Each triangle on the object cannot exceed a 15 degrees deflection between them, so keeping these meshes flat is the best practice.

    For example, this type of breakability within the CryENGINE can be seen in the following screenshot:

    Breaking two-dimensional assets

Designing breakables with constraints

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 submodels spawn on destruction, all the pieces are already rendered.

You can create these within 3ds Max or, alternatively, use a very useful CryENGINE entity called a constraint.

A constraint can be used to hold two physical objects together. The parts can then be individually disjointed by applying physical force greater than the joint limits, by using objects such as 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 as they appear in the real world, as seen in the following screenshot:

Designing breakables with constraints

Note

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 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.

Pop quiz - creating assets for your games

  1. What file format is mostly used for static assets?
    • .chr
    • .cga
    • .cgf
    • .cpp
  2. For creating textures for the CryENGINE game engine, what plugin and tool must be installed when using Adobe Photoshop?
    • CryTIF plugin and extension
    • Max scripts
    • Polybump tool
    • .mel scripts
  3. What entity is best used when creating a destructible asset within the editor?
    • BasicEntity
    • RigidBoxyEx
    • Destroyable object
    • Breakable object
..................Content has been hidden....................

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