@@ -7,19 +7,17 @@ In the next two lessons, we will design the player scene, register custom input
77actions, and code player movement. By the end, you'll have a playable character
88that moves in eight directions.
99
10- .. TODO: add player animated gif?
11- .. player_movement.gif
10+ Create a new scene by going to the ** Scene ** menu in the top-left
11+ and clicking ** New Scene **.
1212
13- Create a new scene by going to the Scene menu in the top-left and clicking *New
14- Scene *.
13+ .. image :: img/02.player_input/new_scene.webp
1514
16- |image0 |
17-
18- Create a :ref: `CharacterBody3D <class_CharacterBody3D >` node as the root
15+ Click the **Other Node ** button and select the ``CharacterBody3D `` node type
16+ to create a :ref: `CharacterBody3D <class_CharacterBody3D >` as the root node.
1917
2018.. image :: img/02.player_input/add_character_body3D.webp
2119
22- Name the :ref: `CharacterBody3D <class_CharacterBody3D >` to ``Player ``.
20+ Rename the :ref: `CharacterBody3D <class_CharacterBody3D >` to ``Player ``.
2321Character bodies are complementary to the area and rigid bodies used in the 2D
2422game tutorial. Like rigid bodies, they can move and collide with the
2523environment, but instead of being controlled by the physics engine, **you ** dictate
@@ -34,20 +32,22 @@ the jump and squash mechanics.
3432For now, we're going to create a basic rig for our character's 3D model. This
3533will allow us to rotate the model later via code while it plays an animation.
3634
37- Add a :ref: `Node3D <class_Node3D >` node as a child of ``Player `` and name it ``Pivot ``
35+ Add a :ref: `Node3D <class_Node3D >` node as a child of ``Player ``.
36+ Select the ``Player `` node in the **Scene ** tree and click the "**+ **" button to add a child node.
37+ Rename it to ``Pivot ``.
3838
3939.. image :: img/02.player_input/adding_node3D.webp
4040
4141Then, in the FileSystem dock, expand the ``art/ `` folder
4242by double-clicking it and drag and
4343drop ``player.glb `` onto ``Pivot ``.
4444
45- | image1 |
45+ .. image :: img/02.player_input/instantiating_the_model.webp
4646
4747This should instantiate the model as a child of ``Pivot ``.
4848You can rename it to ``Character ``.
4949
50- | image2 |
50+ .. image :: img/02.player_input/scene_structure.webp
5151
5252.. note ::
5353
@@ -58,28 +58,29 @@ You can rename it to ``Character``.
5858
5959As with all kinds of physics nodes, we need a collision shape for our character
6060to collide with the environment. Select the ``Player `` node again and add a child node
61- :ref: `CollisionShape3D <class_CollisionShape3D >`. In the *Inspector *, on the *Shape * property, add a new :ref: `SphereShape3D <class_SphereShape3D >`.
61+ :ref: `CollisionShape3D <class_CollisionShape3D >`. In the **Inspector **, on the **Shape ** property,
62+ add a new :ref: `SphereShape3D <class_SphereShape3D >`.
6263
6364.. image :: img/02.player_input/add_capsuleshape3d.webp
6465
6566The sphere's wireframe appears below the character.
6667
67- | image3 |
68+ .. image :: img/02.player_input/sphere_shape.png
6869
6970It will be the shape the physics engine uses to collide with the environment, so
7071we want it to better fit the 3D model. Make it a bit larger by dragging the orange
7172dot in the viewport. My sphere has a radius of about ``0.8 `` meters.
7273
7374Then, move the collision shape up so its bottom roughly aligns with the grid's plane.
7475
75- | image4 |
76+ .. image :: img/02.player_input/moving_the_sphere_up.png
7677
7778To make moving the shape easier, you can toggle the model's visibility by clicking
78- the eye icon next to the ``Character `` or the ``Pivot `` nodes.
79+ the ** eye icon ** next to the ``Character `` or the ``Pivot `` nodes.
7980
80- | image5 |
81+ .. image :: img/02.player_input/toggling_visibility.webp
8182
82- Save the scene as ``player.tscn ``
83+ Save the scene as ``player.tscn ``.
8384
8485With the nodes ready, we can almost get coding. But first, we need to define
8586some input actions.
@@ -94,52 +95,49 @@ arrow keys. In Godot, while we could write all the key bindings in code, there's
9495a powerful system that allows you to assign a label to a set of keys and
9596buttons. This simplifies our scripts and makes them more readable.
9697
97- This system is the Input Map. To access its editor, head to the *Project * menu
98- and select *Project Settings *.
98+ This system is the Input Map. To access its editor, head to the ** Project * * menu
99+ and select ** Project Settings... * *.
99100
100- | image6 |
101+ .. image :: img/02.player_input/project_settings.webp
101102
102- At the top, there are multiple tabs. Click on *Input Map *. This window allows
103+ At the top, there are multiple tabs. Click on ** Input Map * *. This window allows
103104you to add new actions at the top; they are your labels. In the bottom part, you
104105can bind keys to these actions.
105106
106- | image7 |
107+ .. image :: img/02.player_input/input_map_tab.webp
107108
108109Godot projects come with some predefined actions designed for user interface
109110design (see above screenshot). These will become visible if you enable the
110- *Show Built-in Actions * toggle. We could use these here, but instead we're
111- defining our own to support gamepads. Leave *Show Built-in Actions * disabled.
111+ ** Show Built-in Actions * * toggle. We could use these here, but instead we're
112+ defining our own to support gamepads. Leave ** Show Built-in Actions * * disabled.
112113
113114We're going to name our actions ``move_left ``, ``move_right ``, ``move_forward ``,
114115``move_back ``, and ``jump ``.
115116
116- To add an action, write its name in the bar at the top and press Enter.
117+ To add an action, write its name in the bar at the top and press Enter or click the ** Add ** button .
117118
118- | image8 |
119+ .. image :: img/02.player_input/adding_action.webp
119120
120121Create the following five actions:
121122
122- | image9 |
123+ .. image :: img/02.player_input/actions_list_empty.webp
123124
124- To bind a key or button to an action, click the "+ " button to its right. Do this
125- for ``move_left ``. Press the left arrow key and click *OK *.
125+ To bind a key or button to an action, click the "** + ** " button to its right. Do this
126+ for ``move_left ``. Press the left arrow key and click ** OK * *.
126127
127128.. image :: img/02.player_input/left_inputmap.webp
128129
129130Bind also the :kbd: `A ` key, onto the action ``move_left ``.
130131
131- | image12 |
132+ .. image :: img/02.player_input/keyboard_keys.webp
132133
133- Let's now add support for a gamepad's left joystick. Click the "+" button again
134- but this time, select *Manual Selection -> Joypad Axes *.
134+ Let's now add support for a gamepad's left joystick. Click the "**+ **" button again
135+ but this time, select the input within the input tree yourself.
136+ Select the negative X axis of the left joystick under **Joypad Axes **.
135137
136138.. image :: img/02.player_input/joystick_axis_input.webp
137139
138- Select the negative X axis of the left joystick.
139-
140- .. image :: img/02.player_input/left_joystick_select.webp
141-
142- Leave the other values as default and press *OK *
140+ Leave the other values as default and press **OK **.
143141
144142.. note ::
145143
@@ -149,35 +147,18 @@ Do the same for the other input actions. For example, bind the right arrow, D,
149147and the left joystick's positive axis to ``move_right ``. After binding all keys,
150148your interface should look like this.
151149
152- | image15 |
150+ .. image :: img/02.player_input/move_inputs_mapped.webp
153151
154152The final action to set up is the ``jump `` action. Bind the Space key and the gamepad's
155- A button.
153+ A button located under ** Joypad Buttons ** .
156154
157- | image16 |
155+ .. image :: img/02.player_input/joy_button_option.webp
158156
159157Your jump input action should look like this.
160158
161- | image18 |
159+ .. image :: img/02.player_input/jump_input_action.webp
162160
163161That's all the actions we need for this game. You can use this menu to label any
164162groups of keys and buttons in your projects.
165163
166164In the next part, we'll code and test the player's movement.
167-
168- .. |image0 | image :: img/02.player_input/01.new_scene.png
169- .. |image1 | image :: img/02.player_input/02.instantiating_the_model.webp
170- .. |image2 | image :: img/02.player_input/03.scene_structure.png
171- .. |image3 | image :: img/02.player_input/04.sphere_shape.png
172- .. |image4 | image :: img/02.player_input/05.moving_the_sphere_up.png
173- .. |image5 | image :: img/02.player_input/06.toggling_visibility.webp
174- .. |image6 | image :: img/02.player_input/07.project_settings.png
175- .. |image7 | image :: img/02.player_input/07.input_map_tab.png
176- .. |image8 | image :: img/02.player_input/07.adding_action.webp
177- .. |image9 | image :: img/02.player_input/08.actions_list_empty.png
178- .. |image11 | image :: img/02.player_input/09.keyboard_key_popup.png
179- .. |image12 | image :: img/02.player_input/09.keyboard_keys.png
180- .. |image15 | image :: img/02.player_input/12.move_inputs_mapped.webp
181- .. |image16 | image :: img/02.player_input/13.joy_button_option.webp
182- .. |image17 | image :: img/02.player_input/14.add_jump_button.png
183- .. |image18 | image :: img/02.player_input/14.jump_input_action.webp
0 commit comments