Attaching scripts to nodes
I will assume that you already downloaded and looked at the script “cameraMove.gd” from the tile movement Godot Project I posted on Opengameart.
ATTN: You may have tried to play the scene and found that Godot is throwing an error at you. That is because of me being sloppy and calling one function “rotate”, while the same function is “reserved” by Godot for rotating objects. An updated and fixed script will be provided at the end of this post.
Now is the time to copy it from that project into our Godot Project with the dungeon level. For example, put it into “scenes/dungeon/brunstom” folder. Then open the scene (“”test_room”), locate the camera node and select it.
On the right side of the editor, at the very bottom you will find “Script” menu, click to unfold it.
Then drag and drop the “cameraMove.gd” script into the “empty” slot.
NOTE: Pay attention to an additional set of parameters that appeared on the top part of the Inspector. Those came from the script, namely from exported variables. More on this later.
If you play the scene, you will end up with the camera view of the dungeon, but it won’t respond to the keyboard commands. When you look into the script you will see that the commands/actions that the script expects are
These actions are defined and mapped to keyboard keys in the project settings. Go to Project -> Project Settings and click to the “Input Map” tab. There you may see a list of available actions and keys attached to them. There are no action from the list above and will fix that now by adding new actions.
In the Action field enter “ui_step_forward” and click “Add”
At the bottom of the action list a new action will appear with the name “ui_step_forward”. To associate with it keyboard keys, controller buttons or other input device signals press “+” on the right, then select type of the input device (“Key” for our case) and then press keyboard key you want to correspond to “step forward” command. Let’s use WASD scheme and press w (no need to Shift key).
Repeat the steps for the remaining 5 actions, assigning S to step back, A to step left, D to step right, Q to rotate left and E to rotate right. Then press Close.
Now if you play the scene you will see that camera responds to your commands and you can move around the dungeon. Congratulations!
Adjusting Movement Parameters
The parameters that control camera movement come from script, with some of the most important ones exported and shown in the top of the Inspector.
First of all, let’s fix the size of the step from 3.7 to 3, since this is the size of the floor tile. Second of all, let’s reduce the Move Period to 0.5 to make the camera move faster. Save and play the scene.
The default values for these parameters are defined in the script, namely in the part where we “export” variables:
If we change them here to more sensible values, we won’t have to adjust anything in the Inspector.
I suggest you play with parameters, look at the script again and perhaps read online documentation for Godot about scripting.
The scene with the test room and camera with the movement script (correct and tested version) can be downloaded from here.