Skip to content
Benjamin Cronin edited this page Jan 6, 2018 · 2 revisions

Introduction

In this HOWTO I'll explain:

  1. The internal structure of a typical hangar model.
  • The modifications of the model that have to be made in Unity.
  • The minimal part configuration of a hangar (WIP).
  • The process of conversion of an existing part to a hangar (WIP).

Unfortunately, in most cases it's not enough to just write a proper config, because hangars rely on several things in the model; so even if you're just trying to convert some existing part to a hangar, you will need to do a bit of modeling.

Therefor, this HOWTO is intended for the people who already have some experience in 3D modeling, and some knowledge of Unity3D and KSP part making in general. If you are new to all that, I suggest you to start with reading the extensive collection of tutorials and creation of simpler parts.

Also, as I myself use Blender for modeling, all examples will be somewhat specific to this tool, but I'll try to factor out the most important principles.

Hangar's internals

Two things constitute a simple working hangar:

  1. A model designed within certain rules
  2. And the two mandatory MODULEs in the part's .cfg file:
    • Hangar
    • HangarStorage or one of it's derivatives:
      • SimpleHangarStorage
      • SingleUseHangarStorage

The third module usually present in hangars is the HangarAnimator that animates hangar's doors; but neither animated doors, nor this module is really required.

Typical hangar model

A typical hangar is a hollow box with the opening for the doors. This means that the model should have inner and outer surfaces and a set of colliders that outline the space in between:

Inline Hangar

Wall Colliders

The doors, if they are present, also have their colliders, so that a closed hangar has its inner space completely surrounded with them. This allows to also use the hangar as a Cargo Bay (as supported by FAR/NEAR, or the stock game in the future).

Opened Doors Closed Doors

Three very important objects should reside inside the space surrounded by the colliders:

  • hangar-space mesh, which may usually be constructed from the inner surfaces of the colliders.
  • hangar-trigger mesh, which is a simple box that is usually much smaller than hangar-space and is located in the region where the hangar will be checking for incoming ships.
  • launch-position transform (or empty in Blender's terms), which is usually located right at the center of the hangar-space. For hangars with strict launch positioning the local frame of reference of this transform is also used to orient the ship upon launch.

Note, that the names of these objects are not themselves important, but you will need them for the part.cfg later.

space-trigger-position-top space-trigger-position-side

It is very important to note two things here. First, faces of a hangar-space should be oriented inside of it, not outside. Second, the meaning of axes of the launch-position is as follows: green (Y) axis points along the length of a stored/launched rocket to its apex; blue (Z) axis points down, towards its belly.

position-axes

Basically, this is all you need in the model to make a hangar out of it.

Export to Unity and converting to KSP format

Before a model could be used as a part, you need to export it from Blender, import it into Unity, perform several modifications there, and using the PartTools export it finally to the KSP model format.

Export from Blender

In order to use a model in Unity, you need to export it form Blender to the FBX format. The exporter has many options, but all of them may be used at default values, except for the two:

  • Version (of FBX format and exporter), which should be changed to FBX 6.1 ASCII in order to export complex animations properly.
  • Orientation of the axes, which, if you are modeling in normal Blender space (Z is up, Y is forward) should be set as shown in the picture below:

FBX-export

This will rotate the whole model to the Unity native coordinate system, leaving all local reference frames untouched.

Importing into Unity

When you place the exported .fbx file into a Unity project subfolder, it is automatically imported as a prefab. But you need to tweak several options of that prefab to use the imported model. Namely:

  • Change the Scale Factor to 1, and enable mesh compression to improve in-game performance.
  • Change the Animation Type to Legacy.
  • And if you have animated doors, rename the imported animation in a meaningful way. You will need it for the part.cfg later.

Prefab-options1 Prefab-options2 Prefab-options3

Adapting the model

After you have tweaked the prefab, create an empty GameObject in a scene (new or existing) and add the prefab as its child. Then, remove MeshRenderer component from every collider, hangar-space and hangar-trigger.

Remove-MeshRenderer-From Remove-MeshRenderer

Then add the appropriate collider components (Box Collider, Capsule Collider or Mesh Collider) to colliders and hangar-trigger, but NOT to the hangar-space.

Finally, enable the Is Trigger checkbox in the trigger's collider properties:

Is-Trigger

Clone this wiki locally