How to get a boat into DCS

,

How to get a boat into DCS

Mod Note: Hey everyone! I want to thank @TeTeT for offering to put together one of the first articles to be published at Mudspike in quite some time! I hope that we can get back to some ‘long form’ posting in the coming months and years. Thanks again @TeTeT!

Introduction

I want to mimic the Tonkin Gulf incident in DCS and would need a torpedo boat and a F-8 plane for that. As plane modding is completely over the top for a first project in the DCS engine, I settle for a torpedo boat. The P 4 torpedo boats were used by the North Vietnamese navy and the Soviet variant p 123 will be close enough for this.

WARNING

This article is documenting a work in progress and I discover the individual configuration and modeling options as I write this document. Not all workflows are optimal.

Preparations

First we source a model, either self-created or a purchased one. For this tutorial I use a torpedo boat bought from Turbosquid: p123k-komsomolec

I use blender for converting the model into an edm with help of Tobi’s exporter: GitHub - tobi-be/BlenderEdmExporter: Blender EDM Exporter please read the readme

For texturing I rely on Substance Painter.

For creating the configs I use a template provided by Joey45: github DCS-Ship-mod-Template

I edit the lua files in Visual Studio Code: Download Visual Studio Code - Mac, Linux, Windows

I will also upload the config and edm files to github, in a fork of the DCS-Ship-mod-Template:

Setting up the model as edm

In blender I import the obj file from Turbosquid. There is a round display platform below the boat, which I deleted.

Now the boat is too big, by a factor of 10. With the help of the scaling option for objects the size is set to the correct values.

The waterline in DCS is determined by the 0 line in the world coordinates of blender, so I lower the boat appropriately. After these steps the boat looks like this in blender:

Before I rig the model for DCS and edm, I export it as fbx, in case I want to alter the textures later in Substance Painter.

Following the README of BlenderEdmExporter a bone is needed in the blender scene. I create an armature in object mode and use the EDM autorig option on the mesh. The result looks like:

As the EDM tool informs me, there is no material assigned to the boat currently. In the mesh’s material tab I add one, called p4.

Next I add names for the textures: p4, p4_normal and p4_spec:

With that the initial work in blender is done, I export the boat as edm: p4_dcs.edm

Checking the boat in ModelViewer2

The edm file can be checked in a DCS specific program, ModelViewer2. From the DCS mt-bin directory this tool can be launched, and the edm opened. Our boat has the default textures for now:

There is also a standalone ModelViewer2 executable, which might be beneficial. Check DCS World Stand alone Modelviewer quickie and Index of /mods/model_viewer2/ When you copy a mod to the stand alone ModelViewer2 Mods folder, the textures should be autoloaded.

First texturing

The model from Turbosquid comes with a default tga texture. I convert it into DDS with a command line tool, ImageMagick . But any graphical program like gimp or Photoshop can convert the image. I place the resulting p4.dds in a directory named Textures and try to load this into ModelViewer2 via the Tools menu. Unfortunately this does not work and I create a p4.zip with the dds file inside and mount this, stopping ModelViewer2 and restarting it. Then the default diffuse textures are present:

As we neither have a normal nor spec file, I create those via Substance Painter and place them in the zip. After another ModelViewer2 restart, the model is basically textured:

Note that the Soviet star needs to go from the hull eventually, as we want to mimic a North Vietnamese torpedo boat. Maybe it can be replaced by a yellow star.

Initial Configuration

As we want to use github for storing the modding artifacts, I have already forked the repo from Joey45. The p4 torpedoboat will live in a separate branch on that repo. If you’re not familiar with git and github, just download the repo from Joey45 as archive and adjust the files without version control.

Do not be afraid of the many files in the template - they are there to help. We will focus on just a few for getting started: entry.lua, database\Ship Name.lua, Shapes\Name of Ship.lods

Entry.lua

This is the modified entry.lua file. Notes are in the right column

With this entry.lua our project is basically setup, but we need to actually define our ship and its properties next.

Ship Name.lua

As a first step I rename the file to p4.lua, so it has a telling name on what we’re gonna modify here.

As mentioned in the previous section, the p4.lua file will be called indirectly from entry.lua via db_ships.lua. So before we alter p4.lua further, we modify db_ships.lua to call the new file instead of Ship name.lua

db_ships.lua:

Now we have to adjust our main config file.

As the default config is dealing with a much larger ship, an aircraft carrier, we can comment or remove a lot of the definitions there. For getting sensible default values two sources are being used:

As the config is a few hundred lines long, we reference here on github:

Note that there are many lines commented, as we do not need all of the carrier specific information for a torpedo boat.

Name of Ship.lods

This file contains the references to the edm file we produced above from blender. As our edm is named p4_dcs.edm, we rename Name of Ship.lods likewise: p4_dcs.lods. Inside the file we just refer a single lod for now and the same edm serves as collision_shell:

model = {

lods = {

    {"p4_dcs.edm",1000.000000};

};

collision_shell = "p4_dcs.edm";

}

Note that we have not established a collision lod in p4_dcs.edm by now, we merely reference the file now.

First Test in DCS

Now I want to check if the mod basically works. Often this is not the case, so a look into dcs.log is often required and recommended. Search for the name of the mod, p4 in this case, and find information about what might have gone wrong.

For example the first config I wrote for this tutorial had problems with quotes and comments. After fixing them, the following asset was found in the editor:

However, there seems to be an error in dcs.log that I cannot fix:

ERROR Scripting (Main): plugin: tetet_p4 unit replace tetet_p4 not allowed

The value tetet_p4 is used in two places. At the top of entry.lua and in p4.lua.

I suspect that the real problem is that we two time a surface unit, once in entry.lua, once in p4.lua:

add_surface_unit(GT)

I commented out the one on the last line in p4.lua and the error is gone.

Collision Shell

The geometry in the game is defined through the Collision Shell, not the visual representation. In a way so far I created a boat that is for any purpose transparent, but for visuals.

A nice video illustrating the working of the Collision Model in DCS is available at https://www.youtube.com/watch?v=DStv42_FM84

Next I want to add a Collision Shell to the boat. For this I copy my mesh in Blender and reduce it’s complexity and give it a new EDM RenderTag. This image shows the plain copy rigged as Collision Shell.

I have probably removed too much, but this is the first Collision Shell:

Note that only the major pieces of the geometry are left, all ornamental and ‘fragile’ parts have been removed.

Now for a test in the game, I create a mission with an opposing ship that shoots the new p4 torpedo boat.

The first shots of a DDG no longer go through the hull, a big explosion occurs and then the boat sinks.

Armament

(Note: this is outlining the steps I undertook to get the turret working, it’s not necessarily a good work flow in itself. Use with a grain of salt).

In the next step I will rig the dual gun on the aft section of the boat so it can be used for self defense. This part will consist of two pieces:

  1. Configure the weaponry
  2. Modify the model to support the needed animations

Adding armament configuration

In the p4.lua config we omitted so far any new weaponry. In the wikipedia article we find on armament:

2 × 2 12.7 mm (0.50 in) DShK heavy machine guns

For finding the information on how to rig these guns in DCS I look at the dcs lua datamine git repo and search for DShK.

Among many references in Nations, I find the gun mentioned in HL_DSHK.lua and tt_DSHK.lua.

The initial configuration part of the machine guns on the p4 torpedo boat is split in two parts: First a weapon with the needed characteristics is needed and then this weapon is placed in a turret.

For the definition of the weapon I need to find out which ammo is actually used. From wikipedia and gaming I know that the DShK uses a 12.7 mm round, but the best match I find in the dcs lua datamine is the newer Utes round:

_G/db/Units/GT_t/LN_t/machinegun_12_7_utes.lua:
shell_name = { "Utes_12_7x108_T", "Utes_12_7x108", "Utes_12_7x108",

"Utes_12_7x108", "Utes_12_7x108" },

This is close enough for me for now, though I’d be happy to learn which rounds the DShK in DCS actually uses.

The actual table for the weapon configuration is copied from another ship mod and slightly modified with the information I gathered for the DShK.

-- weapon systems goes here

GT_t.WS_t.ship_dshk_2x12mm = {name = "2x12.7mm DShK"};

GT_t.WS_t.ship_dshk_2x12mm.angles = {

{math.rad(180), math.rad(-180), math.rad(-5), math.rad(90)},

};

GT_t.WS_t.ship_dshk_2x12mm.omegaY = math.rad(115) -- Block 1B

GT_t.WS_t.ship_dshk_2x12mm.omegaZ = math.rad(116) -- Block 1B

GT_t.WS_t.ship_dshk_2x12mm.pidY = {p=300, i = 0.05, d = 10.0, inn = 1000};

GT_t.WS_t.ship_dshk_2x12mm.pidZ = {p=300, i = 0.05, d = 10.0, inn = 1000};

GT_t.WS_t.ship_dshk_2x12mm.reference_angle_Z = 0

GT_t.WS_t.ship_dshk_2x12mm.LN = {}

GT_t.WS_t.ship_dshk_2x12mm.LN[1] = {}

GT_t.WS_t.ship_dshk_2x12mm.LN[1].type = 3

GT_t.WS_t.ship_dshk_2x12mm.LN[1].distanceMin = 10

GT_t.WS_t.ship_dshk_2x12mm.LN[1].distanceMax = 1200 -- effective shooting

GT_t.WS_t.ship_dshk_2x12mm.LN[1].max_trg_alt = 500

GT_t.WS_t.ship_dshk_2x12mm.LN[1].reactionTime = 3

GT_t.WS_t.ship_dshk_2x12mm.LN[1].beamWidth = math.rad(1);

GT_t.WS_t.ship_dshk_2x12mm.LN[1].sensor = {}

set_recursive_metatable(GT_t.WS_t.ship_dshk_2x12mm.LN[1].sensor, GT_t.WSN_t[3])

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL = {}

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL[1] = {}

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL[1].ammo_capacity = 2000;

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL[1].shell_name = {"Utes_12_7x108_T", "Utes_12_7x108", "Utes_12_7x108", "Utes_12_7x108", "Utes_12_7x108"};

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL[1].shell_display_name = "12.7mm";

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL[1].shot_delay = 0.08;

GT_t.WS_t.ship_dshk_2x12mm.LN[1].PL[1].reload_time = 15;

GT_t.WS_t.ship_dshk_2x12mm.LN[1].BR =

{ {

pos = { 2, 0, -0.1 }

}, {

pos = { 2, 0, 0.1 }

} }

The DShK as ship armament has now been configured and is available in the boat. Next I need to configure a turret that uses this machinegun. I rely here on another modders work and take the configuration from Aplion as base.

ws = GT_t.inc_ws();

GT.WS[ws] = {}

set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_dshk_2x12mm)

-- GT.WS[ws].area = 'FTURRETSV'

GT.WS[ws].center = 'CENTER_TURRET_01'

GT.WS[ws].drawArgument1 = 0

GT.WS[ws].drawArgument2 = 1

GT.WS[ws].reference_angle_Z = math.rad(5)

GT.WS[ws].angles = {

{math.rad(170), math.rad(40), math.rad(-7.5), math.rad(65)},

{math.rad(40), math.rad(-40), math.rad(0), math.rad(65)},

{math.rad(-40), math.rad(-170), math.rad(-7.5), math.rad(65)},

};

GT.WS[ws].LN[1].BR =

{

{

connector_name = 'POINT_12_7mm_1',


},

{

connector_name = 'POINT_12_7mm_2',


}

};

Now the boat is armed with the dual 12.7mm DShK guns and it’s time for another test. Instead of a DDG I now use the very same boat, a p4 torpedo boat, as blufor opponent.

This time the boat flying the North Korean flag comes out victorious, as good hits are scored on the US torpedo boat.

Note that the shells are emitted from the center of the model, rather than the turret. This comes from the simple fact that in the config I specified non existing connector points in the model, namely CENTER_TURRET_01 and POINT_12_7mm_1 and POINT_12_7mm_2.

Configuring connectors

For animating a turret from scratch with Blender, Tobi, the creator of the EDM exporter, has created a great video, available at https://www.youtube.com/watch?v=eXIl4_Ncoss .

As a first step towards animating the complete rear MG turret I will place these connectors in the model.

In the picture the two points for the guns have been created as an empty object with a cube and the bone is made the parent.

Next the center of the turret is placed.

Again the empty object consisting of the axis is parented to the bone.

In my testing of the gun I unfortunately discover that the bullets still appear from the model center, rather than the defined turret.

Seems what I forgot is to set the Connector EmptyType property in the EDM configuration:

What ultimately revealed this mistake was taking a look in ModelViewer2 → Tools → Connector tools. None were detected, as I had forgotten to set the correct property.

Modeling turret

Following the guide by Tobi mentioned above, we first add bones to the model, then separate the turret and the guns, and animate them via the new bones.

Here we see the two bones for the turret, the vertical one for rotating horizontally, and the diagonal one for animating the elevation of the machine guns.

Here the hierarchy and the focus on the Connected Relation being turned off.

Now the Turret Rear and MGs are separate objects and can be animated via the likewise named bones.

First I animate the turret horizontal turn, fully from 180 to -180 degrees. For the animation I use linear mode, and export it to the EDM with Animation Argument 0. Note that this Animation Argument ties the animation to the configuration:

GT.WS[ws].drawArgument1 = 0

GT.WS[ws].drawArgument2 = 1

Likewise I animate the Rear Turret MG elevation as Animation Argument 1.

Note that I also parented POINT_12_7mm_1 and POINT_12_7mm_2 to the MGs bone, so the connectors rotate and turn with the MGs.

Turret testing

It’s time for another test in game now, to see if the MGs rotate and elevate when acquiring the opposing torpedo boat.

Unfortunately the guns did not engage at all at first. For debugging I removed the connectors for the MGs from the config:

GT.WS[ws].LN[1].BR =
{
    {
         connector_name = 'POINT_12_7mm_1_gone',
    },
    {
        connector_name = 'POINT_12_7mm_2_gone',
    }
};

With this change the guns started to fire, albeit from the rear of the turret, as you can see in the screenshot. Most likely the animation for turning is the wrong way around. Or the configuration is off with the y at 180 degrees:

GT.WS[ws].reference_angle_Y = math.rad(180) -- facing rearward

Seems this angle y is not needed to be 180, as the turret already faced backwards in the model.

After reverting the animation direction, the turret at least faces the general direction, albeit not very precisely.

It turns out that the turret is not facing rearwards exactly on the model.

Another problem is that the barrels are turned downward.

This is probably due to the connectors facing the wrong way?

I first rotate the cubes upwards, hoping that this may help with the problem.

Unfortunately not, but I’m also reminded that I disabled the connectors in the config. After enabling them once more, the situation seems to get worse.

The situation without opposition looks like this.

In the model viewer I see this connector information, but it’s not clear to me what the colors mean.

It seems to be wrong, as the purple line emits from the barrel on a working model:

After some rotations in blender, this looks better:

But it does not work yet, the turret rotates a few degrees and then snaps back to the original position it seems. It’s a bit like a wiggle.

Turret fixing

After inspecting two other mods, it seems that the rear turret is also facing forward in the edm model, not backwards.

Finally it started to work, the turret facing forward, once again changing the direction of the turn animation and adjusting the connectors. Now this setting makes more sense, as it establishes a rear facing turret at start in game:

GT.WS[ws].reference_angle_Y = math.rad(180)

Somehow the bone is misaligned in object mode, but looks ok in edit mode.

Torpedoes

Now with the MG turret working, it’s time to look at the torpedoes. I got help from Hawkeye60 and used his Higgins torpedo boat as a reference.

First I add empty objects with axis in blender, named TPO_01 and TPO_02.

A check in ModelViewer2 reveals that the rotation is not correct for DCS.

So I rotate the empty object in blender so that x goes up and z to the side. In ModelViewer2 the connector is now hidden inside the torpedo tube, so I use the view → wireframe mode to see if it’s aligned correctly

Finally I add configuration to the p4.lua:

ws = GT_t.inc_ws();

GT.WS[ws] = {};

set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_Torpedo84 );

GT.WS[ws].reference_angle_Z = math.rad(5);

GT.WS[ws].LN[1].BR = {

{connector_name = 'TPO_01', recoilArgument = 177, recoilT0 = -1, recoilT1 = -0.5, recoilT2 = 0.5, recoilTime = 1.0},

{connector_name = 'TPO_02', recoilArgument = 178, recoilT0 = -1, recoilT1 = -0.5, recoilT2 = 0.5, recoilTime = 1.0},

};

GT.WS[ws].LN[1].show_external_missile = false

Torpedo testing

In the DCS mission editor I place an unarmed freighter and some boats and see if they are able to sink it.

The boats engage with the machine guns, but the torpedoes stay idle. One of the boats actually passes through the supply ship.

Propellers

After the armament is more or less sorted out, I animate the propellers. There are two of them and I separate them into two objects and connect them with two bones.

I then create a rotation animation on the y axis of each bone and use Animation Argument 2 for this.

In the p4.lua config I add an entry to the animation_arguments table, referring to the Animation Argument.

GT.animation_arguments = {
    water_propeller = 2,
}

Open Issues

  1. Boat wiggles when starting at 0 speed and takes forever to accelerate
  2. Turret animations could be more precise
  3. Torpedoes do not fire

Appendix

On Discord Shisa shared the following advice on rigging ships for DCS:


Addendum

After getting the P 4 torpedo boat into the game more or less easily, I was hopeful that the torpedoes will work out eventually too. It can only be one of those pesky fields with a certain value that needs to be added or modified, right?

Before going into serious debug mode on the P 4 torpedoes, I started doing the opposing side, namely USS Maddox in a circa 1964 layout. This went surprisingly well and, who would have believed it, the destroyer even deployed torpedoes in engagements! Here a screenshot with debug mode of showing the torpedoes.

Equipped with the confidence that I can get torpedoes to work in the game, I went back to the P 4 torpedo boat. I copied the destroyer’s torpedo weapon config, I changed weapon related parameters, I altered the config so it was hardly recognizable anymore. But the torpedoes, they refused to launch. Somewhat frustrated I went to a DCS modding discord and complained about my inability to fire torpedoes … from a torpedo boat!

Now a fellow arma modder, Aplion, took care of the issue. He has already rigged a couple of ships in DCS and has working turret, torpedo and what not configurations. Basically he created a brand new config, based on his working ships rather than the broken one I created, rigged the model fresh in 3ds Max instead of Blender and, of course, the torpedoes worked.

Gladly he shared the config and model with me, so I could go on and inspect what might be wrong. First tests were to see if the new model made a change, or if it’s the config. It turned out to be the config after some testing. As the configs were very different, I decided on a very basic method of eliminating similar config settings. I opened both configs and commented any and all lines that were the same in my original non working config. This meant that only the lines with changes between the configs were left in my original non working config. I gradually applied these changes to the working config, until the working config broke.

Now this was quite a tedious process, as you might guess the faulty config line was of course at the very end of the file. So with the last of many changes applied to the working config, it broke. After testing these last changes line by line I discovered that the faulty entry was an attribute named “Light armed ships” - enabling this attribute would stop the torpedoes from working.

The next hour was spent watching the torpedo boat launching many a torpedo at a defenseless supply ship and see it sink :smiley: Damn the torpedoes!

11 Likes

Fantastic write up

2 Likes

You are doing God’s work here!

1 Like

Added an update at the bottom of the article: How to get a boat into DCS

2 Likes