Create Your First Godot 4 Game
Lesson 7: Creating an enemy
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 22:42
- Lesson 5: Spawning the platforms 8:09
- Lesson 6: Creating a collectible 18:49
- Lesson 7: Creating an enemy
- 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
Let’s not make our raptor too comfortable! In this lesson, we’ll create an enemy character that patrols platforms.
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.
It’s possible for an enemy to occasionally spawn underneath the PlayArea
and never get activated. This is because the PlayArea
is too small compared to the where the platforms can be spawned. This can be fixed by either changing this line in game.gd
:
var y = clamp(last_platform_position.y + rng.randi_range(-150, 150), 200, 1000)
to
var y = clamp(last_platform_position.y + rng.randi_range(-150, 150), 200, 600)
or by increasing the size Y of the RectangleShape2D node under the PlayArea
’s CollisionShape2D from 1200 to 2000.
-
aainflight
April 15, 2024 at 2:29 a.m.great
fusion2k
Nov. 4, 2022 at 3:35 p.m.Small bug in the enemy code, gravity should be: velocity.y += gravity * delta
In the video the + was missing therefore there is no acceleration due to gravity, just a small floating velocity. Not a big problem since these enemies don’t leave the ground (usually) but it’s fun to push them off the platform at this stage :)