Create Your First Godot 4 Game
Lesson 4: Creating the player
Create Your First Godot 4 Game
- Lesson 1: Getting started with Godot 4 2:53
- Lesson 2: Overview of the Godot interface 18:24
- Lesson 3: Setting up the level 11:09
- Lesson 4: Creating the player
- Lesson 5: Spawning the platforms 8:09
- Lesson 6: Creating a collectible 18:49
- Lesson 7: Creating an enemy 10:46
- Lesson 8: Handling player death 10:26
- Lesson 9: Creating the player projectile 13:05
- Lesson 10: Adding the final touches 6:54
- Lesson 11: Exporting your game and wrapping up 2:37
Video Notes
Now things are really going to get interesting! In this lesson, you’ll start creating your player character. You’ll also start learning GDScript, Godot’s custom scripting language.
You can learn the GDScript basics on the Godot website.
Corrections
In Godot 4 Beta 16 or higher, the AnimatedSprite2D’s Playing checkbox has been removed from the Inspector. It has been replaced by the Autoplay button, which can be found in SpriteFrames panel next to the trashcan icon.
Some versions of Godot 4 don’t have the “Listen for Input” option when setting up keybindings. In that case, just use the manual option.
Notes
- Use the “Select/Clear All Frames” button as quick way to select all the frames in a sprite sheet
- If your Player is not showing up in the World scene, make sure your Player scene is saved first
- When getting a reference to the
AnimatedSprite2D
and theCamera2D
, pay attention to the case of the names in the scene. Yours could be different than the ones shown in the video.
If you get stuck, you can compare your code to ours here: https://github.com/quiver-dev/raptor-run. If you’re still stuck, leave a comment here.
-
frostedcookies
Sept. 4, 2023 at 7:29 a.m.I was under the impression that it was a bad idea to scale anything that had a collision shape in it. Is this no longer the case in GD4?
-
amit
Sept. 5, 2023 at 9:25 p.m.That’s a good question. The documentation still recommends not scaling physics bodies, so the best solution is probably scaling the original assets and changing the extents of the collision shape manually. However, we didn’t notice any collision issues or physics instability during testing, so this solution might be good enough.
Juan, the lead Godot dev, did mention that he wanted to support scaling collision shapes in 4.0, but I’m not sure if any work was done towards that in 4. We’ll have to do more research to see if this support has been added or is planned.
-
acesyde
Aug. 13, 2023 at 8:29 p.m.In the last part of this chapter, you should use the compositing pattern by exposing the camera variable like this.
After that in the
main.tscn
you must assign the camera2D to thecamera
variable of thePlayer
.The player component must be not know where the camera is.
amit
Aug. 14, 2023 at 3:14 p.m.Agreed, I think that’s a better way to do in it hindsight. Thanks for pointing that out. This might be a good example to use in a future tutorial about cleaning up code and having a clean separation of concerns.