|
@@ -9,14 +9,31 @@ Anytime you want to use the portal system, you need to include a special node in
|
|
Room Conversion
|
|
Room Conversion
|
|
^^^^^^^^^^^^^^^
|
|
^^^^^^^^^^^^^^^
|
|
|
|
|
|
-This conversion must take place every time you want to activate the system, it does not store the *room graph* in your project (for flexibility and to save memory). You can either trigger it by pressing the **Convert Rooms** button in the editor toolbar when the RoomManager is selected, or you can call the ``rooms_convert()`` method in the RoomManager. This latter method will be what you use in-game. Note that for safety, best practice is to call ``rooms_clear()`` before unloading / changing levels.
|
|
|
|
|
|
+This conversion must take place every time you want to activate the system. It does not store the *room graph* in your project (for flexibility and to save memory). You can either trigger it by pressing the **Convert Rooms** button in the editor toolbar (which also has a keyboard shortcut), or you can call the ``rooms_convert()`` method in the RoomManager. This latter method will be what you use in-game. Note that for safety, best practice is to call ``rooms_clear()`` before unloading or changing levels.
|
|
|
|
|
|
-If you convert the level while the editor is running, the portal culling system will take over from the normal Godot frustum culling. This may affect some editor features. For this reason, you can turn the portal culling on and off, using the **Active** setting in the RoomManager node.
|
|
|
|
|
|
+.. image:: img/convert_rooms_button.png
|
|
|
|
+
|
|
|
|
+If you convert the level while the editor is running, the portal culling system will take over from the normal Godot frustum culling. This may affect some editor features. For this reason, you can turn the portal culling on and off, using either the **View Portal Culling** toggle in the **View** menu on the editor toolbar (which also has a keyboard shortcut), or via the **Active** setting in the RoomManager node.
|
|
|
|
|
|
.. note:: To use the RoomManager, you have to tell it where the rooms are in your scene tree, or rather where the RoomList node is. This RoomList is the parent of your rooms - see below. If the RoomList is not set, conversion will fail, and you will see a warning dialog box.
|
|
.. note:: To use the RoomManager, you have to tell it where the rooms are in your scene tree, or rather where the RoomList node is. This RoomList is the parent of your rooms - see below. If the RoomList is not set, conversion will fail, and you will see a warning dialog box.
|
|
|
|
|
|
.. image:: img/room_manager.png
|
|
.. image:: img/room_manager.png
|
|
|
|
|
|
|
|
+The RoomList
|
|
|
|
+^^^^^^^^^^^^
|
|
|
|
+
|
|
|
|
+Before we create any rooms, we must first create a node to be the parent of all the static objects, rooms, roomgroups and so on in our level. This node is referred to as the the ``RoomList``.
|
|
|
|
+
|
|
|
|
+.. image:: img/roomlist_node.png
|
|
|
|
+
|
|
|
|
+.. note:: The roomlist is **not** a special node type, it can just be a regular Spatial.
|
|
|
|
+
|
|
|
|
+You will need to assign the roomlist node in the RoomManager, so the RoomManager knows where to find the rooms.
|
|
|
|
+
|
|
|
|
+Why do we use a specific branch of the scene tree, and not use the scene root? The answer is that there are many internal details of the system which are easier to manage if the rooms are placed on their own branch.
|
|
|
|
+
|
|
|
|
+Often, you will end up completely replacing the roomlist branch at runtime in your game as you load and unload levels.
|
|
|
|
+
|
|
Rooms
|
|
Rooms
|
|
~~~~~
|
|
~~~~~
|
|
|
|
|
|
@@ -52,12 +69,7 @@ There is one exception however for :ref:`internal rooms<doc_rooms_and_portals_in
|
|
How do I create a room?
|
|
How do I create a room?
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
-A :ref:`Room<class_Room>` is a node type that can be added to the scene tree like any other. You can place objects within the room by making them children and grand-children of the Room node. Instead of placing the rooms as children of a scene root node, you will need to create a Spatial especially for the job of being the parent of all the rooms. This node we will refer to as the ``RoomList``. You will need to assign the roomlist node in the RoomManager, so the RoomManager knows where to find the rooms.
|
|
|
|
-
|
|
|
|
-Room naming convention
|
|
|
|
-^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
-
|
|
|
|
-Unlike most nodes in Godot, a specific naming convention should be followed in order to identify each room. The name should have the prefix ``Room_`` followed by the name you wish to give the room, e.g. ``Room_kitchen``, ``Room_lounge``. If you don't follow these naming guidelines, the system will warn you and may not work correctly.
|
|
|
|
|
|
+A :ref:`Room<class_Room>` is a node type that can be added to the scene tree like any other. You can place objects within the room by making them children and grand-children of the Room node.
|
|
|
|
|
|
How do I define the shape and position of my room convex hull?
|
|
How do I define the shape and position of my room convex hull?
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
@@ -65,8 +77,8 @@ How do I define the shape and position of my room convex hull?
|
|
Because defining the room bound is the most important aspect of the system, there are THREE methods available to define the shape of a room in Godot:
|
|
Because defining the room bound is the most important aspect of the system, there are THREE methods available to define the shape of a room in Godot:
|
|
|
|
|
|
1. Use the geometry of the objects contained within the room to automatically create an approximate bound.
|
|
1. Use the geometry of the objects contained within the room to automatically create an approximate bound.
|
|
-2. Provide a manual bound. This is a MeshInstance in the room that has geometry in the shape of the desired bound, with a name prefixed by ``Bound_``. This is something you might choose to do if you create your levels in Blender or similar (see :ref:`doc_rooms_and_portals_blender`).
|
|
|
|
-3. By manually editing the points that define the convex hull, in the room inspector.
|
|
|
|
|
|
+2. By manually editing the points that define the convex hull, in the room inspector, or dragging the points using the editor gizmo (see :ref:`doc_room_point_editing`).
|
|
|
|
+3. Provide a manual bound. This is a MeshInstance in the room that has geometry in the shape of the desired bound, with a name with a postfix ``-bound``. This is something you might choose to do if you create your levels in Blender or similar (see :ref:`doc_rooms_and_portals_blender`).
|
|
|
|
|
|
While the first option can be all that is required, particularly with simple rooms, or for pre-production, the power of the manual bounds gives you ultimate control (at the expense of a small amount of editing). You can also combine the two approaches, perhaps using automatic bounds for most rooms but manually editing problem areas.
|
|
While the first option can be all that is required, particularly with simple rooms, or for pre-production, the power of the manual bounds gives you ultimate control (at the expense of a small amount of editing). You can also combine the two approaches, perhaps using automatic bounds for most rooms but manually editing problem areas.
|
|
|
|
|
|
@@ -83,25 +95,23 @@ If you create some rooms, place objects within them, then convert the level in t
|
|
|
|
|
|
:ref:`Portal<class_Portal>`\ s are special convex polygons. You position over the openings between rooms, in order to allow the system to see between them. You can create a portal node directly in the editor. The default portal has 4 points and behaves much like a ``plane`` :ref:`MeshInstance<class_MeshInstance>`. You can add or remove points using the inspector. A portal will require at least 3 points to work - this is because it needs to form a polygon rather than a point or line.
|
|
:ref:`Portal<class_Portal>`\ s are special convex polygons. You position over the openings between rooms, in order to allow the system to see between them. You can create a portal node directly in the editor. The default portal has 4 points and behaves much like a ``plane`` :ref:`MeshInstance<class_MeshInstance>`. You can add or remove points using the inspector. A portal will require at least 3 points to work - this is because it needs to form a polygon rather than a point or line.
|
|
|
|
|
|
-Portals only need to be placed in one of each pair of neighbouring rooms (the *"source room"*). The system will automatically make them two way unless you choose otherwise in the portal node's properties. The portal normal should face *outward* from the source room. The front face should be visible from *outside* the room. The editor gizmo indicates the direction the portal is facing with an arrow, and a different color for each face.
|
|
|
|
|
|
+To save editing effort, **only one Portal is required between each pair of Rooms**. You *do not need* to (and indeed should not) create two Portals that overlap in opposite directions. Portals default to being two-way (but you can make them one-way in the Portal inspector).
|
|
|
|
|
|
-.. image:: img/portal_inspector.png
|
|
|
|
|
|
+You should therefore place a portal in only one of each pair of neighbouring rooms - this is the portal's *"source room"*. Generally it doesn't matter which you choose as the source room. The portal normal (the arrow in the gizmo) should face *outward* from the source room.
|
|
|
|
|
|
-Like rooms, portals also follow a naming convention which is as follows:
|
|
|
|
|
|
+.. image:: img/portal_inspector.png
|
|
|
|
|
|
-- Prefix ``Portal_``.
|
|
|
|
-- Optional : You can add a suffix of the room that the portal will lead to ('destination room'). E.g. ``Portal_kitchen``. This name is not just descriptive; it affects behavior when converting rooms (see below).
|
|
|
|
|
|
+Do not be confused by the arrow. Although the arrow shows which direction the portal faces, most portals will be *two-way*, and can be seen through from both directions. The arrow is more important for ensuring that the portal links to the correct neighbouring room.
|
|
|
|
|
|
-The suffix is optional. In many cases, the system can automatically detect the nearest room that you intended to link to and do this for you. It is usually only in problem areas you will need to use the suffix.
|
|
|
|
|
|
+Portal linking
|
|
|
|
+^^^^^^^^^^^^^^
|
|
|
|
|
|
-In rare cases, you may end up with two or more portals that you want to give the same name, because they lead into the same destination room. However, Godot does not allow duplicate names at the same level in the scene tree. The solution to this is the wildcard character ``*``. If you place a wildcard at the end of the name, the rest of the characters will be ignored. For example, ``Portal_Kitchen*1`` and ``Portal_Kitchen*2``.
|
|
|
|
|
|
+There are two options for dealing with specifying which room the portal should link to.
|
|
|
|
|
|
-All in all there are three ways of specifying which room a portal should link to:
|
|
|
|
-- Leaving the name suffix blank to use auto-linking.
|
|
|
|
-- Add suffix to the Portal node's name.
|
|
|
|
-- Assigning the **Linked Room** in the inspector for a Portal node. This is simply a shortcut for setting the name by renaming the node.
|
|
|
|
|
|
+- Leave the **Linked Room** in the inspector blank. The system will attempt to *autolink* the portal to the nearest neighbour room during conversion. This works fine in most cases.
|
|
|
|
+- You can explicitly specify the room by setting the **Linked Room** in the inspector.
|
|
|
|
|
|
-.. note:: Portals have some restrictions to work properly. They should be convex, and the polygon points should be in the same plane. The snapping of points to a plane is enforced because portal points are only defined in 2D (with X and Y coordinates). The node transform is used to convert these to world-space 3D points. The node transform thus determines the portal orientation.
|
|
|
|
|
|
+.. note:: Portals are defined as a set of 2D points. This ensures that the polygon formed is in a single plane. The transform determines the portal orientation. The points must also form a *convex* polygon. This is enforced by validating the points you specify, ignoring any that do not form a convex shape. This makes editing easier while making it difficult to break the system.
|
|
|
|
|
|
Trying it out
|
|
Trying it out
|
|
~~~~~~~~~~~~~
|
|
~~~~~~~~~~~~~
|