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.
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: MyGameFolderScriptsEntitiesVehiclesImplementationsXml
.
Open the MyVehicle.max
scene made from the previous recipe to use as a reference for the parts section within this recipe.
Basic Properties:
MyVehicle.XML
.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">
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:
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>
<Parts>
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>
<Parts>
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).<body>
tag:<Part name="massBox" class="MassBox" mass="1500" position="0,0,1." disablePhysics="0" disableCollision="0" isHidden="0"> <body> tag<MassBox size="1.25,2,1" drivingOffset="-0.7"/> </Part>
<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>
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: VehiclesMyVehicle
. 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)!
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.The def_vehicle.xml
file found in MyGameFolderScriptsEntitiesVehicles
, holds all the property's definitions that can be utilized in the XML of the vehicles. After following the recipes found in this chapter, you may want to review def_vehicle.xml
for further more advanced properties that you can add to your vehicles.
3.144.30.62