Using the Rotation Controller

From C4 Engine Wiki

Jump to: navigation, search

The demo game that ships with C4 contains a generic controller that can be used to rotate objects in a world. It can be assigned to a single object or a group of objects in the World Editor to make them rotate about a given axis. No coding is required. In this example, we will assign a rotation controller to a box and tell it to rotate the box around an off-center axis. (The axis was chosen to be off-center simply to make the screenshots more clear.)

Contents

Step 1 — Create the necessary nodes

The rotation controller uses three nodes to do its job. The first node is the node that it will actually cause to rotate. This can be any node in the scene, and it is the node to which the rotation controller will be assigned below. The other two nodes are locator markers that define the axis about which the first node is rotated. So we begin by creating a new world and then drawing a box and two locator markers. (Select the Markers page from the Page menu to access the Locator Marker tool.) The two locator markers should be placed so that the imaginary line connecting them represents the axis about which the box will rotate. The distance between the locators is not important and can be chosen to be anything that is convenient. In the screenshot below, the two locators are aligned so that the line between them is parallel to the vertical (z) axis.


Image:rotate1b.png


Step 2 — Create the connectors

The rotation controller looks for two connectors on the node that it is assigned to. These connectors link the rotating node to the two locator markers so that the controller knows what axis to rotate about. To create the connectors, select the box and hit Ctrl-I (Cmd-I on the Mac) to open the Get Info dialog. Then go to the Connectors pane and click the New button at the bottom of the pane twice. Fill in the two connector identifier fields with the four-character codes CENT and AXIS, in either order. Be sure to use capital letters because the rotation controller looks for these exact codes. You may choose Marker from the node type menus next to the identifiers, but this isn't strictly necessary. After creating the two connectors, the dialog should look like the following screenshot. Click OK (or hit Enter) to close the dialog.


Image:rotate2b.png


Step 3 — Connect the connectors

Once the connectors have been created, we need to link them to the two locator markers. This is done using the Select and Connect tool, which is described in more detail in the Using Connectors article. Select the CENT connector and link it to one of the locator markers, then select the AXIS connector and link it to the other locator marker. Once this step is complete, you should see something similar to the following screenshot. (Note that reversing the connector assignments will reverse the direction of rotation.)


Image:rotate3b.png


Step 4 — Assign and configure the controller

The final step is to assign the rotation controller to the box. Select the box and hit Ctrl-I to open the Get Info dialog again. Go to the Controllers pane and select the Rotation controller from the list. The settings for the rotation controller will appear in the window as shown below.


Image:rotate4b.png


The “Initial speed” setting specifies the speed at which the node will rotate, in revolutions per second. The other settings can be ignored for an object that will rotate at a constant speed. See below for a description of the more advanced settings.


Advanced rotation settings

If the “Restrict to angle range” box is checked for a rotation controller, then the rotation moves through a specific range of angles and then stops. The “Start angle” and “Finish angle” settings specify where the rotation starts and finishes, measured in revolutions (i.e., the number 1.0 represents a full 360 degrees).

The “Initially disabled” flag indicates that the rotation controller is initially in the stopped state. The rotation can be started by using a script to change the rotation controller's state.

The “Initially reversed” flag indicates that the rotation will initially go in the direction opposite to the normal direction.

Controlling rotation from a script

The rotation controller defines two functions that can be called from a script. To use them, add a Call Function method to a script and select a target node that has a rotation controller assigned to it.

The “Change Rotation Speed” function smoothly changes the rotation speed to a new value over a given period of time.

The “Set Rotation State” function allows you to set or clear the disabled and reversed flags for a rotation controller.

Personal tools