Using the Mover Controller
From C4 Engine Wiki
Status: C4 2.0
Contents |
Introduction
This page provides information regarding the implementation and usage of the Mover controller introduced in C4 2.0. In addition to a general overview, a list of important notes and observations is included, and it should be read by anyone interested in using the Mover controller. Finally, the last section of this page includes a step-by-step tutorial for implementing a simple elevator. It is aimed at beginners with little to no prior working knowledge of the World Editor.
A topic has been created in the support forums for this article here. It is used to store a world file containing a working example of the Mover controller: elevator.zip. The world file was designed in a similar fashion described in this tutorial to act as a reference for those trying to work through it. Any questions or comments regarding this article should be directed to that topic.
Using the Mover Controller
Copied from the forums, this is a brief explanation of what is needed to use the Mover controller. This will probably be rewritten later to better suit this article.
You need two markers, one to act as the start point and one to act as the end point. You need to create a geometry, assign a physics shape to it, and make sure collisions are enabled for the geometry. In the Node Info dialog for the geometry, go to the controller tab and select the Mover controller. You'll need to go to the Connector tab and add two connectors, which need to be attached to the start and end markers created earlier. The name of these markers need to correspond with the names in the Mover controller as seen in the controller tab.
To activate the controller you need a script on another node (trigger, panel, etc.). Connect that other node to your geometry, and in the script you'll have the ability to use the CallControllerFunction method. Make one, and open it. Set the target node and you should see some functions to run the mover.
Important Notes
- Assigning the Mover controller to a rigid body means that the rigid body will not have friction, so while it will lift other rigid bodies, any small force on them will cause them to slide off.
- The Mover controller controls a rigid body. When the Mover controller is not doing anything, that rigid body is asleep and will not be affected by external forces. When the rigid body is being moved it is affected by external forces, which will add to the velocity set for the rigid body. This means that an external force will change the velocity and tragectory of the rigid body being used to move the player. Once the Mover controller sees that the rigid body has moved the correct distance, it positions it at its destination, which is not very noticeable if the rigid body had been moving along its original path.
- The rigid body being controlled by the Mover controller cannot come into contact with a geometry that is not controlled by a rigid body controller, including walls made of static geometry. A very small small gap must be between it and other static geometries at all times. This small gap will cause some small issues for the player's movement, but Eric is working on some code that should fix it.
- The Mover controller uses the position of the node when determing the path of movement. This means that wherever the NodePosition is calculated (in the case of a box it is one of the corners) will be moved to the the markers.
- The markers defining the start and end points of the Mover controller's path must also be positioned so that their centers do not correspond with a geometries surface (i.e. a small gap must be between them and any non rigid body geometry).
- Currently work is being done by Terathon that will resolve some or all of these issues.
Simple Elevator Tutorial
Setting up the World
1) Create a new world. To do this, start C4 and press the tilde(`) key. Select New World in the toolbar that shows up .
2) Using the Page menu, enable the Effects, Lights, Markers, and Physics pages.
3) Open the Material Manager through the Material page. Three materials will be used in total: one for the ground, one for the elevator, and one for the object that we want to get to the top of. One blank material is provided by default, so to create the two additional materials, press the New button twice. It may be useful to name them (Ground, Elevator, and Wall). To assign textures to the materials, click the arrow in the Texture map (primary) field and navigate to the Data/Demo/texture folder and select a texture for each material. For added depth, the Normal map (primary) field can be set to the normal map for the primary texture set.
4) Right-click in one of the non-perspective viewports, or ctrl+right-click in the perspective viewport to bring up a menu. Select the Scene Graph option to display the scene graph in that viewport. Double-click on the infinite zone node to bring up the Node Info window and select the properties tab. Select Clear Color from the Available Properties list and click assign. Set the color desired for the background and close the window.
5) Select the material to be used for the ground and close the Material Manager. Select the plate geometry in the Geometry page and in the top view place a plate in the scene. This will act as the ground for the world. Return to the Material Manager and select the wall material. Exit the Material Manager and place a box geometry in the scene. The elevator will carry the player to the top of this geometry.
6) Select the infinite light from the Lights page and place one in the scene.
7) Select the Spawn marker from the list in the Markers page and place it somewhere above the plate geometry. This will be where the player model spawns when the world is loaded.
8) Select the Physics node from the Physics page and place one in the scene. Without it the engine will not enable the built in physics.
Making the elevator
1) After selecting the elevator material from the Material Manager, place a relatively flat box geometry in the scene close to the ground and adjacent to the box that the elevator takes the player to the top of. See the notes below for important information on placing this box. This box will be used as the elevator
2) In the Physics page, select the box shape and place it in the scene at the same position as the box geometry being used as the elevator. It should be the same size and shape as it. In the scene graph viewport, use the movement tool to move this physics shape to the elevator geometry, making it a subnode of that geometry.
3) In the Node Info dialog for the elevator geometry, click on the Controllers tab. Programmers can program controllers and register them in the World Editor so that they appear here, then artists can simply assign controllers to nodes in the World Editor without having to assign them in code.
4) Select the Mover controller from the list to assign it to the elevator geometry. The Mover controller uses two markers to designate its end points. By default, it expects the markers to be named 'begn' and 'endg', but these can be changed in the fields for the Mover controller in the Controller tab of the Node Info window.
5) Select the Connectors tab in the Node Info window and create two connectors using the New button. Name these connectors so that they correspond with the two names in the Controller page. Exit the Node Info window.
6) In the Markers page select the marker icon. Place one marker close to the ground to act as the beginning marker. Because Mover controller only allows for up and down movement, it should have the same X and Y coordinates as the gizmo (the one that shows the axes for the node) that appears when the box is selected. The location of this gizmo will be the point of the geometry used to move it between the markers. This marker should also be slightly (0.00001 units is enough, and is not noticeable) above the ground. See the note below for why this is.
7) Place another marker in the scene directly above the first where the elevator should stop.
8) Select the box geometry being used for the elevator and hit the Connect Nodes button above the viewports. Two connectors should appear in the non-perspective viewport coming from the selected geometry. The names on them will correspond to the names from the connectors created earlier. Select the connector designated for the beginning marker, then select the beginning marker. In the Node menu at the top of the World Editor, select Connect Nodes. A link should appear between the connector and the marker. Repeat this using the ending marker and the connector designated for it.
9) In the effects page select the panel effect and create a panel as a subnode of the elevator. It should be at a height and position where the player can reach it while standing on the elevator. This panel will be used to setup buttons to control the elevator.
10) Select the panel, and in the Connectors tab of the Node Info window create a connector to connect the panel with the elevator geometry. Then close the Node Info window. Link this connector to the geometry by selecting the panel and hitting the Connect Nodes button like before. Select the connector, then select the elevator geometry. In the Node menu select Connect Nodes to create a link between the two.
11) Make sure the panel is selected and go to the Properties Page in its Node Info window. Select the Interaction property in the Available Properties list and press the Assign button. As the name indicates, this lets the player interact with the panel.
12) Go to the controller page and make sure that the Controller Type is set to Panel and then press the Edit Panel button.
13) Place two Image items in the panel to act as buttons, one for making the elevator go up and one for making it go down.
14) Select the item intended to be a button that makes the elevator go down and press the Edit Script button. Each item in a panel can have a script attached to it. In the Methods pane at the left, choose the Call Controller Function method from under the Basic tab and place it in the script. Open the Method Info window for it by double clicking on it. If the panel was properly connected to the elevator, it's connector should appear in the list of Target Nodes. Select it and a list of functions should appear. These are the functions associated with the Mover controller. Select the Move to Beginning Position function and press the OK button. Repeat this for the 'up' button in the panel, but using the Move to Ending Position function. When the player presses these buttons on the panel they will now cause the elevator to move.
15) Save the world and play it.
