Working with Portals
From C4 Engine Wiki
In order to allow for arbitrarily large and complex environments, every world built in the C4 Engine World Editor needs to be organized into multiple zones. The root node of a world is an infinitely large zone, and all other zones are contained within the root zone. When new zones are added to a world, they need to be connected by portals so that it's possible to see from one zone into another. This tutorial describes a simple example in which two rooms are connected by a pair of portals.
To follow this tutorial, you need the Data/Tutorial/world/Portal.wld file that is included in the Data.zip distribution.
Contents |
Step 1 — Prepare Portal.wld
Open Data/Tutorial/world/Portal.wld in the World Editor by typing Ctrl-O or by entering world Tutorial/world/Portal into the command console. The World Editor should contain a scene that looks like the screenshot below.
This world contains two zones, each of which contains a very simple room with a light source in it. The world already contains portals that lead from each room into the other, so you'll need to delete them first if you want to follow the rest of this tutorial.
A direct portal is shown as a greenish outline with green arrows attached to it. (There are other types of portals that are different colors, but a direct portal is the basic type that lets you see from one room to another.) To delete the two portals in this world, simply select each one and hit the Delete key. To select the portals in some viewports, it may be necessary to disable zone selection using the selection mask so that a zone isn't inadvertently selected. You may also find it easiest to change one of the viewports to the scene graph display and select the portals there.
Step 2 — Draw the first portal
To fully connect the two zones, one portal needs to be added to the left room that looks into the right room, and another portal needs to be added to the right room that looks into the left room. (That is, portals are one-way.) We'll begin by creating the portal that leads from the left room to the right room.
First, select the zone for the left room, and select Set Target Zone from the Node menu (or press Ctrl-T) to make the zone the current target zone. The striped zone boundary enclosing the left room will turn green to indicate that it's the current target zone. Whenever a new node is created in the World Editor, it is placed in the current target zone.
Next, go to the Page menu and select the Portals page. The Portals page will appear on the left side of the editor. Select the green portal icon that represents direct portals. Drag out a rectangular portal in the upper-right viewport (viewport #2) exactly where the opening between rooms is. After doing this, the viewports should look like the screenshot below.
Step 3 — Rotate the portal
The portal appears at the left end of the target zone, and it's facing to the left. We need to turn it around so that it's facing toward the other room and move it to the boundary between the zones. Use the Move Nodes tool (shortcut: press 2) to move the portal into the center of the room, and then use the Rotate Nodes tool (shortcut: press 3) to rotate the portal by 180 degrees. The best way to perform the rotation is to turn on the Draw from Center mode (using the button at the top of the editor), so that the portal rotates about its center. Hold the shift key while rotating to use the angle snap feature. Once the portal is rotated correctly, it should appear as in the screenshot below.
Step 4 — Move the portal into place
Now use the Move Nodes tool to put the portal on the zone boundary as shown below. (Ctrl-1 was used to fill the editor window with viewport #1).
Step 5 — Connect the portal to a zone
Once the portal is in its final position (and still selected), select the Connect Nodes tool (shortcut: press 5). A box containing the word "ZONE" will appear next to the portal, and a yellowish arrowed line will point out of the box. This is the connector that indicates which zone the portal leads to. By default, a portal is connected to the zone in which it resides (which has the effect of disabling the portal). To connect the portal to the other zone, choose Auto-connect Portal from the Node menu or press Ctrl-Shift-L. This will cause the portal to be connected to the right zone, and the line emanating from the connector box should now point to the center of the new destination zone.
Step 6 — Draw the second portal
The other portal is somewhat easier to create in this case. First, select the right zone, and then select Set Target Zone from the Node menu (or press Ctrl-T). The right zone should now turn green to indicate that it is the current target zone, and the left zone will turn back to yellow. Now draw another portal in the same place that the first portal was drawn, covering the opening between rooms. (You may need to unselect the "Draw from Center" mode.) This time, the portal will already be in the correct position with the correct orientation, as shown in the screenshot below. While the portal just drawn is still selected, again select Auto-link Portal from the Node menu to link the new portal to the left zone. You may then select the Connect Nodes tool to verify that the portal is connected to the correct destination zone.
Step 7 — See the result
Save the world, close the editor, and type load portal in the command console. You can now see between the two rooms, and light shines from one room into the other, as shown in the final screenshot below.
Common Problems with Portals
- Make sure that one of the zones isn't accidentally a subzone of the other when you didn't intend it to be. You can tell by looking at the node hierarchy in the scene graph viewport. A zone can be re-parented by selecting it in the scene graph viewport and using the Move Nodes tool to drag it to the proper parent zone, which is usually to infinite zone at the root of the scene.
- Make sure each portal is in the zone that it leads out of. This can also be checked in the scene graph viewport.
- Make sure each portal is connected to the zone that it leads into. You can always see this by selecting the portal and clicking the Connect Nodes tool (or using the shortcut 5). The ZONE connector should point to the center of the destination zone.







