-
Notifications
You must be signed in to change notification settings - Fork 333
Custom Doors
- Misc RMB models (RmbBlock.Misc3dObjectRecords) For example like graveyard blocks seem to use for the entrance building model for some reason. Solution is to move the model data into RmbBlock.RmbSubRecord.Exterior.Block3dObjectRecords using RMB override.
- Interior dungeon models (RdbObjects) Use the "Entrance/Exit - Standalone" model from the 'WDE Dung. Parts' list (modelId 70300)
These are doors that allow transition to building or dungeon interiors from a RMB exterior. The model can be a replacement of a classic DF modelId or a completely new custom model. The model should be imported into unity editor then placed into a prefab named with the modelId you're using. The model file can be named whatever you want and doesn't need adding to the files list in mod builder. Same goes for model textures, but they still need to be visible to unity (e.g. in a textures folder) even for unchanged classic models since the prefab is referencing the png's. Using this modelId in any RMB data files will then use this prefab.
If you are using a custom modelId then all doors will have to be defined using CustomDoor components since the classic door data won't be available.
If your model is replacing a standard DF model with a new or modified model (i.e. using the classic modelId and therefore affecting all blocks the model is used in) then you can also utilise the copy door mechanism detailed below if desired or define custom doors just like for new modelId's. To disable classic model doors from being active, check DisableClassicDoors on any CustomDoor component in your prefab to disable all classic model doors on this model.
Remember to put a start marker flat near the external door in the interior, which should also be near the corresponding internal door. (WDE Billboards->Markers 'Marker : Enter') The player will be placed at the nearest start marker when entering. When exiting, the nearest external door to the internal door used is selected and the player placed in front of it. (check 'Show Editor Flats' on StartGameBehaviour to show markers so you can see where they are)
To add a custom door to your model prefab, add a CustomDoor component which will also automatically add a BoxCollider component. To use the standard mechanism the StaticDoorCopied field should keep the the default value of '-1'. Select the appropriate door type, either Building or DungeonEntrace (defaults to building), then use the edit button on the box collider to define the door bounds. (no need to worry about trigger or material)
You can only manipulate each face with this unity tool, so I've found it best to load a preset for either X or Z facing doors to set the size, and then altering the x,y,z position of the collider in the inspector to position it where desired. The presets set the size to (1.25, 2.25, 0.5) for Z facing doors, or (0.5, 2.25, 1.25) for X facing. You can make any size and position you want, just ensure that the dimension going into the door is smaller than the other two so the door normal can be calculated, and that the bounds intersect the exterior of the model where you want the door to be activated so hit registration works.
Adding more than one door to the prefab can be done by adding new CustomDoor component and BoxCollider component and then dragging the collider into the CustomDoor DoorTrigger field. This is awkward because the names of the colliders in the CustomDoor components are identical so you can't easily see which is attached to which. Probably fine for a few doors but hard to manage for many.
To avoid this you can add the new BoxCollider a child GameObject which is named however you want. (to do this right click on the model GameObject in the prefab hierarchy and 'Create Empty' and rename it to "door2" for example. (you can call it whatever you want) Then select this and add a BoxCollider component in inspector and edit the bounds and position like before. Switch back to the model GameObject and add a new CustomDoor component and change the settings as required. Link this to the BoxCollider you just added using the name used. Repeat for any other doors you want.
In this example the first door BoxCollider, door 0 in this case, is on the model GO 43760 and then 2nd (door1) and 3rd (door2) are in child GO's, but use whatever naming convention is best. (non-programmers usually start counting from 1 rather than 0 for instance)
If replacing a standard DF model with a new or modified model (i.e. using the classic modelId) then the original copy mechanism can be used, as it's been kept for backwards compatibility. To do this, everything is the same as described above, but you set the StaticDoorCopied to the door index number that you want the CustomDoor to use the StaticDoor data of instead of calculating new data. This might be used if the custom doors are just moving a little, but generally this mechanism is only retained for backwards compatibility and in case someone finds it useful. In this case the nearest original door is used for exit positioning. Note that if all original doors on the model are disabled and all new CustomDoor components use the copy mechanism then the exit player positioning doesn't work since there's no door data, so be sure to define at least one CustomDoor that doesn't copy if disabling original doors.
Internal custom doors work in the same way for building interiors. You can either use existing classic model pieces which have doors defined as shown in the WDE below. The flat single faces ('Single Exit - blah') can be pasted over any wall, assuming textures match. Alternatively you can define custom doors on an interior model prefab in the same way as for external doors. Either way remember to add a start marker.
-
First model in RmbSubRecord is used for hit registration for the building so it should be the main / largest model with the doors. Other models can have doors, but they need to be in the bounding box used for building hit registration. (1% larger than model size)
-
Pausing the game and switching to Unity Scene view can be used to see the door surfaces the game has registered. Find the model and select it. (I usually go to the location in game and click on PlayerAdvanced to center the view there, pan and select the model) Then if you select the parent block object, or interior, then if gizmos are on you will see the defined static doors the game knows about as you can see in this example. Green lines are the custom door box colliders you added to the prefab and the blue surface, with direction line, is where the game thinks the door is.
-
For any angled doors not facing a cardinal direction, use the box collider as a topdown diamond with the corners intersecting the sides of the door like shown below. The smallest X or Z size will be the direction player is placed when exiting, thankfully this placement to the side isn't that noticable.
-
For Y facing (trap-)doors I recommend using a cube shape with the Y size slightly smaller, as shown here for an untextured 'trapdoor'.