Adding an Enemy Character

From C4 Engine Wiki

Jump to: navigation, search

This tutorial demonstrates how an enemy character is added to a world and how it is awoken by a trigger. The spider model from the demo game is used here, but the same steps apply to any character that a game uses.

First, open the world to which you'd like to add an enemy character and select the zone in which the character will start. Make sure that zone is the current target zone by hitting Ctrl-T (Cmd-T on the Mac). In this tutorial, we use the Lasers world in the Data/Tutorial/world/ directory.

If the Models page is not already visible in the editor, select it from the Page menu. Then select the model to be placed in the world and click in the top viewport where the model should be placed. If the Show Models toggle button is on, then the model will be shown directly in the world after you click. Otherwise, you will only see a cube representing the model's origin position. The model will appear at the bottom of the zone in which it is placed. In the case of the Lasers world, the model needs to be moved up a little so that it stands on the floor correctly. Once the model has been moved into position, the Lasers world will look like this:



Next, we add a trigger box to the world that will be used to awaken the spider model when the player walks through it. If the Triggers page is not already visible, select it from the Page menu. Then select the Box Trigger tool and draw a rectangle in the top viewport as shown in the screenshot below.



Now we add a connector to the trigger that we just created that will link to the spider model. With the trigger box still selected, hit Ctrl-I (Cmd-I on the Mac) to open the Node Info window. Click on the Connectors tab, and then click on the New button to create a new connector. Give the new connector any four-character identifier you want—we chose SPID for this example. You may also select Model from the node type menu so that this connector can only be linked to a model node. Once this connector is set up, your Node Info window should look like this:



Hit OK to exit the Node Info window and then select the Connect Nodes tool (for a shortcut, just hit the 5 key). Click on the new connector that you just created, and it will be highlighted. Now click on the cube representing the spider model to select it. Hit Ctrl-L (Cmd-L on the Mac) to link the connector to the model. Your world should now look like the following:



Now switch back to the ordinary Select Nodes tool (shortcut 1), and select the trigger node again. We need to tell the engine what to do when the player enters the trigger box. Hit Ctrl-I to bring up the Node Info window, and then click on the “Disabled after activation” checkbox under the Trigger tab. This causes the trigger to disable itself right after it is first activated by a player. The Node Info window should look like this:



Go to the Controller tab and select Script from the list of available controllers. A new button labeled Edit Script will appear below the list as shown below:



Click the Edit Script button and you'll see a blank script window. Switch the the Standard tab under the Methods heading, and select the Wake Controller method. Click anywhere in the script viewport to place this method in the script. The script editor should now look like this:



The final step is to Hit Ctrl-I while the Wake Controller method is selected to open its Method Info window. Here, we can select a target for the Wake Controller method. Choose the SPID connector that you made earlier (as shown below) and hit OK. This step completes the very simple script that tells the spider to wake up when the players enters the trigger.


Personal tools