Advertisement

CryENGINE 3 Cookbook Sample Chapter: How To Create A New Vehicle In CryENGINE 3

by

Today we're continuing our CryENGINE 3 Cookbook giveaway, and giving you a chance to get a sneak peak at some of the content this amazing book has to offer. Below you'll find the third and final sample chapter we'll be publishing from the book. If you haven't already entered for your chance to win a copy, find out how after the jump!

Fall is finally here and we're kicking it off in style by teaming up with Packt Publishing to give you a chance to win one of three copies of their highly anticipated CryENGINE 3 Cookbook, authored by Crytek's own Dan Tracy and Sean Tracy. With the recent release of CryENGINE 3 this is the perfect time to jump in and start working with one of the most powerful game engines in the industry.




SAMPLE CHAPTER

How To Create A New Vehicle In CryENGINE 3

In this article we will explore some advanced components of CryENGINE 3 by creating a new vehicle for your player to drive around in your level.

In this article by Dan Tracy, author of CryENGINE 3 Cookbook, we will cover:

  • Creating a new car mesh (CGA)
  • Creating a new car XML
  • Giving more speed to the car
  • Increasing the mass to push objects with the car
  • Defining a sitting location
  • Setting up multiple cameras for the car
  • Need for a machine gun
  • Giving the car a weak spot

Creating a new car mesh (CGA)

In this recipe, we will show you how to build the basic mesh structure for your car to be used in the next recipe. This recipe is not to viewed as a guide on how to model your own mesh, but rather as a template for how the mesh needs to be structured to work with the XML script of the vehicle. For this recipe, you will be using 3DSMax to create and export your .CGA.

.CGA (Crytek Geometry Animation): The .cga file is created in the 3D application and contains animated hard body geometry data. It only supports directly-linked objects and does not support skeleton-based animation (bone animation) with weighted vertices. It works together with .anm files.

Getting ready

Create a box primitive and four cylinders within Max and then create a new dummy helper.

How to do it...

After creating the basic primitives within Max, we need to rename these objects. Rename the primitives to match the following naming convention:

  • Helper = MyVehicle
  • Box = body
  • Front Left Wheel = wheel1
  • Front Right Wheel = wheel2
  • Rear Left Wheel = wheel3
  • Rear Right Wheel = wheel4

Remember that CryENGINE 3 assumes that y is forward. Rotate and reset any x-forms if necessary.

From here you can now set up the hierarchy to match what we will build into the script:

1. In Max, link all the wheels to the body mesh.
2. Link the body mesh to the MyVehicle dummy helper.

Your hierarchy should look like the following screenshot in the Max schematic view:

Next, you will want to create a proxy mesh for each wheel and the body. Be sure to attach these proxies to each mesh. Proxy meshes can be a direct duplication of the simple primitive geometry we have created.

Before we export this mesh, make one final adjustment to the positioning of the vehicle:

1. Move the body and the wheels up on the Z axis to align the bottom surface of the wheels to be flushed with 0 on the Z.
2. Without moving the body or the wheels, be sure that the MyVehicle helper is positioned at 0,0,0 (this is the origin of the vehicle).
3. Also, re-align the pivot of the body to 0,0,0.

Once complete, your left viewport should look something like the following screenshot (if you have your body still selected):

After setting up the materials, you are now ready to export the CGA:

1. Open the CryENGINE Exporter from the Utilities tab.
2. Select the MyVehicle dummy helper and click the Add Selected button.
3. Change the export to: Animated Geometry (*.cga).
4. Set Export File per Node to True.
5. Set Merge All Nodes to False.
6. Save this Max scene in the following directory: MyGameFolder\Objects\vehicles\MyVehicle\.
7. Now, click on Export Nodes to export the CGA.

How it works...

This setup of the CGA is a basic setup of the majority of the four wheeled vehicles used for CryENGINE 3. This same basic setup can also be seen in the HMMWV provided in the included assets with the SDK package of CryENGINE 3.

Even though the complete HMMWV may seem to be a very complicated mesh used as a vehicle, it can also be broken down into the same basic structure as the vehicle we just created.

The main reason for the separation of the parts on the vehicles is because each part performs its own function. Since the physics of the vehicle code drives the vehicle forward in the engine, it actually controls each wheel independently, so it can animate them based on what they can do at that moment. This means that you have the potential for a four wheel drive on all CryENGINE 3 vehicles, all animating at different speeds based on the friction that they grip.

Since all of the wheels are parented to the body (or hull) mesh, this means that they drive their parent (the body of the vehicle) but the body also handles where the wheels need to be offset from in order to stay aligned when driving. The body itself acts as the base mesh for all other extras put onto the vehicle. Everything else from Turrets to Doors to Glass Windows branch out from the body.

The dummy helper is only the parent for the body mesh due to the fact that it is easier to export multiple LODs for that vehicle (for example, HMMWV, HMMWV_LOD1, HMMWV_LOD2, and so on). In the XML, this dummy helper is ignored in the hierarchy and the body is treated as the parent node.

There's more...

Here are some of the more advanced techniques used.

Dummy helpers for modification of the parts

A more advanced trick is the use of dummy helpers set inside the hierarchy to be used in later reference through the vehicle's mod system. How this works is that if you had a vehicle such as the basic car shown previously, but you wanted to add on an additional mesh just to have a modified type of this same car (something like adding a spoiler to the back), then you can create a dummy helper and align it to the pivot of the object, so it will line up to the body of the mesh when added through the script later on.

This same method was used in Crysis 2 with the Taxi signs on the top of the Taxi cars. The Taxi itself was the same model used as the basic civilian car, but had an additional dummy helper where the sign needed to be placed. This allowed for a clever way to save on memory when rendering multiple vehicle props within a single area but making each car look different.

Parts for vehicles and their limitless possibilities

Adding the basic body and four wheels to make a basic car model is only the beginning. There are limitless possibilities to what you can make as far as the parts on a vehicle are concerned. Anything from a classic gunner turret seen on the HMMWV or even tank turrets, all the way to arms for an articulated Battlemech as seen in the Crysis 2 Total Conversion mod—MechWarrior: Living Legends. Along with the modifications system, you have the capabilities to add on a great deal of extra parts to be detached and exploded off through the damage scripts later on. The possibilities are limitless.


Creating a new car XML

In this recipe, we will show you how to build a new script for CryENGINE 3 to recognize your car model as a vehicle entity. For this recipe, you must have some basic knowledge in XML formatting.

Getting ready

Open DefaultVehicle.xml in the XML editor of your choice (Notepad, Notepad++, UltraEdit, and so on). This XML will be used as the basic template to construct our new vehicle XML.

DefaultVehicle.xml is found at the following location: MyGameFolder\Scripts\Entities\Vehicles\Implementations\Xml.

Open the MyVehicle.max scene made from the previous recipe to use as a reference for the parts section within this recipe.

How to do it...

Basic Properties:

1. First, we will need to rename the filename to what the vehicle's name would be.
2. Delete filename = Objects/Default.cgf.
3. Rename name = DefaultVehicle to name = MyVehicle.
4. Add actionMap = landvehicle to the end of the cell.
5. Save the file as MyVehicle.XML.
6. Your first line should now look like the following:

Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

<Vehicle name="MyVehicle" actionMap="landvehicle">

7. Now we need to add some physics simulation to the vehicle otherwise there might be some strange reactions with the vehicle. Insert the following after the third line (after the Buoyancy cell):

<Simulation maxTimeStep="0.02" minEnergy="0.002" maxLoggedCollisions="2"/>

Damages and Components:

For now, we will skip the Damages and Components cells as we will address them in a different recipe.

Parts:

1. To associate the parts made in the Max file, the hierarchy of the geometry in 3DSMax needs to be the very same as is referenced in the XML. To do this, we will first clear out the class = Static cell and replace it with the following:

<Part name="body" class="Animated" mass="100" component="Hull">
<Parts>
</Parts>
<Animated filename="objects/vehicles/MyVehicle/MyVehicle.cga"
filenameDestroyed="objects/vehicles/HMMWV/HMMWV_damaged.cga"/>
</Part>

2. Now, within the tag that is underneath the body, we will put in the wheels as the children:

<Parts>
<Part name="wheel1" class="SubPartWheel" component="wheel_1" mass="80">
<SubPartWheel axle="0" density="0" damping="-0.7" driving="1" lenMax="0.4"
maxFriction="1" minFriction="1" slipFrictionMod="0.3" stiffness="0" suspLength="0.25" rimRadius="0.3" torqueScale="1.1"/>
</Part>
</Parts>

3. Remaining within the tag, add in wheels 2-4 using the same values as previously listed. The only difference is you must change the axle property of wheels 3 and 4 to the value of 1 (vehicle physics has an easier time calculating what the wheels need to if only two wheels are associated with a single axle).

4. The last part that needs to be added in is the Massbox. This part isn't actually a mesh that was made in 3DSMax, but a generated bounding box, generated by code with the mass and size defined here in the XML. Write the following code snippet after the tag:

<Part name="massBox" class="MassBox" mass="1500" position="0,0,1."
disablePhysics="0" disableCollision="0" isHidden="0">
<MassBox size="1.25,2,1" drivingOffset="-0.7"/>
</Part>

5. If scripted correctly, your script should look similar to the following for all of the parts on your vehicle:

<Parts>
<Part name="body" class="Animated" mass="100" component="Hull">
<Parts>
<Part name="wheel1" class="SubPartWheel" component="wheel_1" mass="80">
<SubPartWheel axle="0" density="0" damping="-0.7" driving="1" lenMax="0.4"
maxFriction="1" minFriction="1" slipFrictionMod="0.3" stiffness="0" suspLength="0.25"
rimRadius="0.3" torqueScale="1.1"/>
</Part>
<Part name="wheel2" class="SubPartWheel" component="wheel_2" mass="80">
<SubPartWheel axle="0" density="0" damping="-0.7" driving="1" lenMax="0.4"
maxFriction="1" minFriction="1" slipFrictionMod="0.3" stiffness="0" suspLength="0.25"
rimRadius="0.3" torqueScale="1.1"/>
</Part>
<Part name="wheel3" class="SubPartWheel" component="wheel_3" mass="80">
<SubPartWheel axle="1" density="0" damping="-0.7" driving="1" lenMax="0.4"
maxFriction="1" minFriction="1" slipFrictionMod="0.3" stiffness="0" suspLength="0.25"
rimRadius="0.3" torqueScale="1.1"/>
</Part>
<Part name="wheel4" class="SubPartWheel" component="wheel_4" mass="80">
<SubPartWheel axle="1" density="0" damping="-0.7" driving="1" lenMax="0.4"
maxFriction="1" minFriction="1" slipFrictionMod="0.3" stiffness="0" suspLength="0.25"
rimRadius="0.3" torqueScale="1.1"/>
</Part>
</Parts>
<Animated filename="objects/vehicles/MyVehicle/MyVehicle.cga"
filenameDestroyed="objects/vehicles/HMMWV/HMMWV_damaged.cga"/>
</Part>
<Part name="massBox" class="MassBox" mass="1500" position="0,0,1."
disablePhysics="0" disableCollision="0" isHidden="0">
<MassBox size="1.25,2,1" drivingOffset="-0.7"/>
</Part>
</Parts>

Movement Parameters:

Finally, you will need to implement the MovementParams needed, so that the XML can access a particular movement behavior from the code that will propel your vehicle. To get started right away, we have provided an example of the ArcadeWheeled parameters, which we can copy over to MyVehicle:

<MovementParams>
<ArcadeWheeled>
<Steering steerSpeed="45" steerSpeedMin="80" steerSpeedScale="1" steerSpeedScaleMin="1"
kvSteerMax="26" v0SteerMax="40" steerRelaxation="130" vMaxSteerMax="12"/>
<Handling>
<RPM rpmRelaxSpeed="2" rpmInterpSpeed="4" rpmGearShiftSpeed="2"/>
<Power acceleration="8" decceleration="0.1" topSpeed="32" reverseSpeed="5" pedalLimitMax="0.30000001"/>
<WheelSpin grip1="5.75" grip2="6" gripRecoverSpeed="2" accelMultiplier1="1.2" accelMultiplier2="0.5"/>
<HandBrake decceleration="15" deccelerationPowerLock="1" lockBack="1" lockFront="0"
frontFrictionScale="1.1" backFrictionScale="0.1" angCorrectionScale="5" latCorrectionScale="1" isBreakingOnIdle="1"/>
<SpeedReduction reductionAmount="0" reductionRate="0.1"/>
<Friction back="10" front="6" offset="-0.2"/>
<Correction lateralSpring="2" angSpring="10"/>
<Compression frictionBoost="0" frictionBoostHandBrake="4"/>
</Handling>
<WheeledLegacy damping="0.11" engineIdleRPM="500" engineMaxRPM="5000" engineMinRPM="100"
stabilizer="0.5" maxTimeStep="0.02" minEnergy="0.012" suspDampingMin="0" suspDampingMax="0"
suspDampingMaxSpeed="3"/>
<AirDamp dampAngle="0.001,0.001,0.001" dampAngVel="0.001,1,0"/>
<Eject maxTippingAngle="110" timer="0.3 "/>
<SoundParams engineSoundPosition="engineSmokeOut" runSoundDelay="0" roadBumpMinSusp="10"
roadBumpMinSpeed="6" roadBumpIntensity="0.3" maxSlipSpeed="11"/>
</ArcadeWheeled>
</MovementParams>

After saving your XML, open the Sandbox Editor and place down from the Entities types: Vehicles\MyVehicle. You should now be able to enter this vehicle (get close to it and press the F key) and drive around (W = accelerate, S = brake/reverse, A = turn left, D = turn right)!

How it works...

The parts defined here in the XML are usually an exact match to the Max scene that the vehicle is created in. As long as the naming of the parts and the name of the subobjects within Max are the same, the vehicle structure should work.

The parts in the XML can themselves be broken down into their own properties:

  • Name: The name of the part.
  • Class: The classification of the part.
  • Base (obsolete)
  • Static: Static vehicle (should not be used).
  • Animated: The main part for an active rigid body of a vehicle.
  • AnimatedJoint: Used for any other part that's used as a child of the animated part.
  • EntityAttachment (obsolete)
  • Light: Light parts for headlights, rear light, and so on.
  • SubPart (obsolete)
  • SubPartWheel: Wheels.
  • Tread: Used with tanks.
  • MassBox: Driving Massbox of the vehicle.
  • Mass: Mass of the part (usually used when the part is detached)
  • Component: Which component this part is linked to. If the component uses useBoundsFromParts="1", then this part will also be included in the total bounding box size.
  • Filename: If a dummy helper is created in Max to be used as a part, then an external mesh can be referenced and used as this part.
  • DisablePhysics: Prevents the part from being physicalized as rigid.
  • DisableCollision: Disables all collision. It is an useful example for mass blocks.
  • isHidden: Hides the part from rendering.
There's more...

The def_vehicle.xml file found in MyGameFolder\Scripts\Entities\Vehicles, holds all the property's definitions that can be utilized in the XML of the vehicles. After following the recipes found in this article, you may want to review def_vehicle.xml for further more advanced properties that you can add to your vehicles.


Giving more speed to the car

Now that we have created a basic template for a car within the game, we can now start manipulating more of the fun properties that the XML holds. Let us start out by giving this car a bit more speed.

Getting ready

Complete the Creating a new car XML recipe. Then open MyVehicle.xml in Notepad or an equivalent editor.

How to do it...

Under the cell, you will find the tag; within the tag you will find a property called topSpeed=32. It is a simple matter of increasing this value to increase the car's overall top speed.

How it works...

The Arcade Wheeled movement property is a new movement behavior since CryENGINE 3. Dealing away with the confusing gear ratios, new backend code has been written to create the Arcade Wheeled for the purpose of being able to tweak the major values on wheeled vehicles much easier.

There's more...

The following are the common properties of an Arcade Wheeled:

  • Acceleration: How fast the vehicle will speed up
  • Decceleration: How fast the vehicle will slow down
  • TopSpeed: Top speed that the vehicle can achieve
  • ReverseSpeed: Reversing speed
  • Handbrake-decceleration: Deceleration when hand brake is applied

Increasing the mass to push objects with the car

In this recipe, we explore some of the possibilities of manipulating the Massbox that we created when first creating the car's XML. With increasing the Massbox of the car, we will see how the car is able to push lighter objects out of the way.

Getting ready

Complete the Creating a new car XML recipe. Then open MyVehicle.xml in Notepad or an equivalent editor.

How to do it...

As simple as the previous recipe was, this one will be just as easy to make a massive change to your vehicle.

Begin by finding the car's part named massBox. To increase the mass of the MassBox, simply increase the mass = 1500 to a higher value such as 3500.

The mass in CryENGINE 3 is measured in kilograms.

How it works...

A simple method to see the results of how easy it is for the car to move objects out of its way is to place down a basic entity with a mass of 1000 and then drive into it with the previous MassBox properties. Then repeat the process again with the 3500 MassBox value.

After changing any XML values on the car, you can reload the XML on the car by right-clicking on the vehicle and selecting Reload Scripts.

The MassBox is a special part of the vehicle that handles all of the physical interactions of the vehicle as a whole. Along with Arcade Wheeled as the movement behavior, the Massbox is the main point of reference for the car and all its parts for mass physics calculations (as long as all those parts remain on the vehicle).

Be aware that increasing the mass of the MassBox will also change the driving characteristics of the car.

There's more...

It is possible to define the mass of other parts besides the Massbox. However, with Arcade Wheeled movement parameters, this property change will do virtually nothing, but with other movement behaviors it may change the driving mechanics such as the Wheeled Legacy (which should not be used as that movement behavior is no longer supported).

Still, there is a use of this property and that is if ever we want to create a part to be detached from the vehicle, this part requires a mass in order to follow the laws of physics for the CryENGINE, such as gravity.


Defining a sitting location

Up to this point, we haven't addressed the issue of the player hanging out of the side of the vehicle every time the they enter it. This is due to the fact that there is no sitting position defined for the driver position and thus leaves the player in the last position and pose before entering the vehicle. In this recipe, we will fix this problem by creating a new helper within the vehicle XML.

Getting ready

Complete the Creating a new car XML recipe. Then open MyVehicle.xml in Notepad or an equivalent editor.

How to do it...

1. Between the and cells, you will need to insert the following lines into the car XML:

<Helpers>
<Helper name="driver_sit_pos" position="-0.75,0.25,1.5"direction="0,1,0" part="body"/>
</Helpers>

2. After writing in the Helpers cell, we now need to define on the driver seat which helper the player needs to take in order to be positioned in that seat.
3. For the cell, you will need to change the following property:
sitHelper=""
4. Change this value to:
sitHelper="driver_sit_pos"
5. Save the XML and reload the car in the level.

How it works...

This simple seat helper lets the vehicle code know where the passengers of that particular seat need to be positioned in the vehicle. Be aware that this only aligns the root pivot of the character to this position. So in order to pose a character to sit in this position, it is a good practice to create a new animation graph and animation that moves the character so that the root pivot aligns to a bone on the character such as the pelvis.

There's more...

You can use the HMMWV animation graph to give a seated position to your character. If no changes to the player model have been made to the skeleton, then we will be able to utilize the animation graph from the SDK's HMMWV to pose our character. Within the same cell, add the following property:
agVehicleName="HMMWV"

This will use the animation graph to play the same animations used for entering and exiting the vehicle as well as utilizing the same sitting pose as the one used for the HMMWV.


Setting up multiple cameras for the car

In this recipe, we will demonstrate how you can set up different cameras at different positions to be utilized within the game. We will demonstrate some of the basic views such as First Person and Third Person as well as the popular Wheel rim camera usually used in action replays in various other media.

Getting ready

Complete the Creating a new car XML recipe. Then open MyVehicle.xml in Notepad or an equivalent editor.

How to do it...

First Person Camera:

1. After the Creating a new car XML recipe, we should already have the majority of what we need in the cells. For our first camera, we will utilize the cell to make a new first person camera that we can also look around with.
2. First, we will need a new Helper. Copy the following into the cells:

<Helper name="driver_view" position="-0.75,0.35,2.0" direction="0,1,0" part="body"/>

3. Now, define this driver_view helper in the empty FirstPerson.helper property:

<FirstPerson helper="driver_view" />

4. To allow the player to look around in this First Person view, we will need to add/change the properties in the FirstPerson class to match the following line:

<View class="FirstPerson" canRotate="1" rotationMin="-45,0,-170" rotationMax="45,0,170">

The rotationMin and rotationMax are measured in degrees.

5. You may need to tweak the position a bit, but the result should look something like the following screenshot:

By default, F1 toggles the player's camera. This also works within vehicles.

Third Person Camera:

Since the creation of the car, the Third Person camera is basically set up. However, we may want to adjust some of the properties to the following:

<ThirdPerson distance="3" heightOffset="2.5" speed="1" />

This will bring the overall distance a little closer, push up the camera's height as well as slow down the camera to induce a little bit of lag, allowing the car to move further ahead of the camera a bit when driving really fast or lag a bit on sharp turns.

Wheel Camera:

1. This is a bonus camera that may add a bit of fun when cycling between cameras. To make this camera, we will need to first create a new view. Copy the following into your .

<View class="FirstPerson" canRotate="0">
<FirstPerson helper="wheel_cam" />
</View>

2. Next, we need to create a new helper for this camera:

<Helper name="wheel_cam" position="1.9,-0.5,0.5" direction="0,1,0" part="body"/>

This position will depend on the body of the vehicle and the position of the wheels from the mesh.

3. In the end, the desired affect is a Wheels Camera that resembles something like the following screenshot:

How it works...

Just like defining a helper position for the sitting position, helpers can be used in a number of different places on the XML and the cameras are no different. Utilizing the positions and directions of the helpers, you will be able to create some interesting camera positions of your own.

There's more...

Some additional cameras such as SteerThirdPerson and ActionThirdPerson (no longer supported) can also be utilized as other styles of cameras when the player is sitting in the seat of the vehicle. You can find their properties from def_vehicle.xml (MyGameFolder\Scripts\Entities\Vehicles).


Need for a machine gun

In this recipe, we will do something fun with the car and attach a machine gun to the vehicle and have it be fired from the driver's seat.

Getting ready

Complete the Creating a new car XML recipe. Then open MyVehicle.xml in Notepad or an equivalent editor. Delete the following cells from MyVehicle.xml:

<Weapons>
<Primary/>
</Weapons>
<ActionParts/>

How to do it...

In the cells that were just deleted (as they were obsolete), copy the following lines:

<SeatActions>
<SeatAction class="Weapons">
<Weapons isSecondary="0">
<Weapons>
<Weapon class="AsianCoaxialGun" part="body">
<Helpers>
<Helper value="mgun_out"/>
</Helpers>
</Weapon>
</Weapons>
</Weapons>
</SeatAction>
</SeatActions>

How it works...

The newly added tag is used for any weapons that are made for the vehicles. The weapon itself can use a helper to fire from and if the weapon is set up on a part, then the weapon will rotate with that part as well (such as a turret).

The flag of isSecondary handles whether the weapon is fired from the primary fire button or if it uses the secondary fire button.


Giving the car a weak spot

From the Creating a new car XML recipe, we skipped the Damages and Components section of the XML. Now it is time to return to that section and give this car a weak spot.

Getting ready

Complete the Creating a new car XML recipe. Then open MyVehicle.xml in Notepad or an equivalent editor.

How to do it...

1. We need to first create a new cell in between and . Copy the following code snippet to that location:

<Damages submergedRatioMax="0.6" submergedDamageMult="1" collDamageThreshold="10"
groundCollisionMinMult="1.3" groundCollisionMaxMult="1.4" groundCollisionMinSpeed="8"
groundCollisionMaxSpeed="22">
<DamageMultipliers>
<DamageMultiplier damageType="bullet" multiplier="0.125"/>
<DamageMultiplier damageType="collision" multiplier="1"/>
</DamageMultipliers>
<DamagesGroups>
<DamagesGroup name="Destroy" useTemplate="CarDestroy">
</DamagesGroup>
</DamagesGroups>
</Damages>

2. The tag here handles the global damage done to the entire vehicle, such as if the vehicle is submerged under water, collisions with the entire vehicle, global damage multipliers (which will be further explained in the How it works... section) and also the tag, which usually handles the destruction of the vehicle.
3. Next, we will need to create the components of the vehicle:

<Components>
<Component name="Hull" damageMax="100" position="0,0.5,1" size="2.5,4,2" useBoundsFromParts="0">
<DamageBehaviors>
<DamageBehavior class="Group" damageRatioMin="1">
<Group name="Destroy"/>
</DamageBehavior>
</DamageBehaviors>
</Component>
<Component name="weakspot" damageMax="100" position="0,-2,1" size="2.5,1,2" useBoundsFromParts="0">
<DamageMultipliers>
<DamageMultiplier damageType="bullet" multiplier="1"/>
</DamageMultipliers>
<DamageBehaviors>
<DamageBehavior class="Group" damageRatioMin="1">
<Group name="Destroy"/>
</DamageBehavior>
</DamageBehaviors>
</Component>
</Components>

4. The two components set previously create two different bounding boxes. One is the main hull, which wraps around 85 percent of the vehicle at the front, while the other is the weakspot, which covers the back.

How it works...

Since the components do not overlap each other, this allows for the vehicle to respond differently when the vehicle gets hit in either location. In this example, we have set up a DamageMultiplier on the weakspot component to be much higher for bullets. This will make sure the bullet damage it receives is not reduced and will quickly reach the component's maximum health limit of 100. When that happens it will call the damage behaviour group Destroy, which was written at the beginning of the recipe.

The damage group Destroy uses the DamagesTemplate called CarDestroy. This template is a global DamageBehaviour that's written in an external XML and can be accessed from other vehicle XMLs for ease of setup.

The DefaultVehicleDamages.xml can be found in the following location: MyGame\Scripts\Entities\Vehicles\DamagesTemplates\.

There's more...

Additional damage behaviors can be utilized such as Burn, Effect (particle effects), Explosion (with impulse), HitPassenger, and many more. See def_vehicle.xml for the complete list.

Summary

In this article we saw how to create a new vehicle from scratch and set up the entity code required so your players can drive.


About the Author :

Dan Tracy

Dan Tracy is Crytek’s Technical Level Designer for the award-winning CryENGINE and Crysis 2. He is responsible for the creation and maintenance of numerous technical features and external applications used for telemetry and optimization. Viewed as more than a level designer, Dan prides himself on pushing the envelope when it comes to improving both technical and game related designs across multiple production disciplines. Dan was recruited by Crytek in 2009 after the previous year working as a Quality Assurance Technician for BioWare. He was recruited due to his pivotal role in co-founding and leading development on the award winning total conversion project ‘MechWarrior:Living Legends’. Since then, he has been featured in numerous gaming magazines and has been interviewed by multiple media outlets. Dan is a passionate gamer, but an even more passionate modder and game designer with vast knowledge and experience with multiple engines and titles including Never Winter Nights’ “Aurora”, Battlefield’s engine “Frostbite”, Unreal 3, and CryENGINE.




Editor's note: This post was sponsored by Packt Publishing.

Advertisement