Space Rocks! Godot Tutorial Part 10
Key Takeaways
Builds a space-themed game using Godot Game Engine, exploring solutions and refactoring code
Full Transcript
welcome back this is part 10 of space rocks the video game engine tutorial where we're making a full asteroid style game if my voice is a little rough I apologize I was out for a while with a cold that's why the gap before this video but now I'm back to it and in this installment we're going to add some enemies to the game so that the player has a little bit more of a challenge okay let's get started so for this installment I've decided to start adding an enemy a little flying saucer bad guy that's going to spawn every once in a while and kind of move across the screen shooting at the player and I'm going to use the flying saucer yeah looks like salsa art we have here so let's start it let's make a scene for that I'm going to make a new scene this one I'm going to start it with an area 2d and we're going to do that because we just want to be able to know if a bullet or the player enters this enters this area so we note that it got hit all right and we're going to add a few nodes under here we're going to add a sprite we're going to add a collision 2d and we're going to add an animation player and I'll show you why we're doing that in a minute but first of all let's rename these I'm going to call this sprite this is the collision and and I'm going to name the animation player just an M for short so we can put the sprite I'm going to use the green one there you go I think it's a little bit on the large side so I'm going to scale it down just a little bit for the collision we're going to use a going to use a circle shape we'll make a circle shape and just make that the size of the texture okay let's save this in our scenes enemy good now the reason I added this animation player note is I want to have this inside the collision for a second I want to have this flying saucer look like it's spinning so I'm going to use the animation player to give it a spin because we want to basically take the sprite rotation parameter and have it steadily change so what we need to do is we need to make a new animation we'll just tall call this rotate and now we get a little timing track here all right the default length is one second and it steps by 0.1 0.1 so play the animation right it just goes from there to there well at the beginning of the track we want our sprites rotation or the sprites rotation is what we're going to alter so if we go over here to sprite and rotation we see a little key and we can click that to add a new keyframe for the transform slash rot property and that's going to be set at zero I then move the play back to halfway along the track so I'm going to have one point five seconds I'm going to change this to 180 degrees and I'm going to click keyframe again so now it's rotating from side step along it smoothly interpolates between those two alright and back here at 1 we want to go to 360 which is a full rotation all right so now as we eat and of course I've got to add it as a keyframe got to click the key there we go so now we've got a full rotation if we hit play right so we'll click this and make it a loop this button now if I hit play there we've got a spinning spaceship and what we can also do is on an animation here we can alter the speed like maybe I'll slow it down a little half the speed you know maybe maybe 0.6 there we go so now that'll just continue to rotate constantly playing back this animation alright now we want to make this this guy fly around the screen and I've thought about a few different ways of doing that right we could go over here and we could just have a timer and we instance it every once in a while and spawn it off the screen somewhere and have it move you know across the screen and exit on the opposite direction or something like that but that's kind of boring I like to have them kind of fly around in various paths so for now and I'm not sure if I'm going to permanently do it this way but this is the way I've come up with for now what I'm going to do is I'm going to make a new scene and the route of this is just going to be a node and this is going to be called enemy path let's save this and all we're going to make in this enemy pav's scene is some path 2d nodes that will describe some paths that this that this spaceship can follow and if you're unfamiliar with the path 2d I did do a little video on it which I'll link to below on how you use the path follow which is what we're going to do once we have the path drawn so I'm going to skip the drawing the path apart so I'll be right back with some redrawn paths ok we're back and I have I've added three different paths to the nodes to this scene the first one which is going to start over on the left and just sort of move through move directly across the screen I have this Center 1 which kind of is just going to start up the top and around and then I have the third one which is going to come in and do a big loop through the center of the screen before it goes off the opposite side and so these three paths are going to be just randomly so we're going to randomly select one when we spawn an enemy and just have it follow so if you're not familiar with path 2d it's very easy to work with you know you just use these little control buttons up here to create to create the points of your curve and then also grab the handles to control the path right you can drag these around and change things around and I'm okay with these you know later it'll be easier for us to adjust these and replace them with different paths move them out change them around however we want because the codes just going to load these load this scene we're just going to instance the scene and pick one of these nodes out of it all right so what's on our enemy we're just going to add an instance of that of that enemy path node so that we will be able to exit all right so now let's make a script on the enemy so I've gone ahead and made one here and so we're going to get a reference to to that enemy path node so we can use it and then there's a few other variables we're going to need we're going to need to choose which path out of those children we're going to we're going to follow we're going to need to make a path follow 2d node and we are going to need to create a remote node which I will we'll get into in a second and we're going to set our speed help stops we want our little Flying Saucer to travel so in the ready let's set process to true let's randomize and so the first step is we need to pick that random path well if we do pass get children that gets the full list of that gives us an array holding all those children and so we want to select one of them and when we want to select is just a random number mod to get child count and then we will have a random path now we need to create that path Solow to denote that's the one that that's the one that's going to actually trace the path along that and so we add that and we need to add that as a child to the path now we've got our path followed to D now we need to create our remote node and that's just going to be a node to D it's going to be a child of follow and the reason for that is when you use the path fellow to denote the child any child of this path follow to D is what will follow the path which is what will have its coordinates set to the coordinates along the path so it needs to be a child so we're going to this is just going to be a placeholder node to D that's going to follow the path and then we're going to set our enemy's position to match it okay so that's it so now we've created all the nodes we need and actually you can see if we run this if we look at the remote inspector you'll see we've hopefully selected Path number two we made our path follow and then there's our node to D as a child of it now we just need to do the movement so in our process we're going to take the follow and set the offset to whatever the offset currently is plus our speed times Delta and that's going to make this node 2d move so we just need to set the position of our main node our area 2d to whatever the remotes global position is and that should do it so let's give it a try there we go looks like we're following the one that just half done the one that started at the bottom and went up here but we are looping by default when you create a path all of 2d you get a you get a loop meaning when it when the offset reaches the maximum it goes right back to the start I'm just trying it a couple of times do see us do another path here we go I think this is the one that's going to go up and around that's good so we don't want it to we don't want it to loop so if we go over here we can say follow that set loop to false because we're going to want to be spawned the Flying Saucer when it reaches the edge but you also might have noticed that when we run it our flying saucer isn't spinning right our animation isn't playing how come that is the case right here when you look at it in the inspector right animation is set to play it's active how come well there's an option right here autoplay on load you need to set that if you don't set that then in your script you have to go here and tell the animation to play in the ready okay there we go now we have our nice little spinning flying saucer I like it and now what we want to do is just do a cue free when we leave the screen so we're going to use a visibility notifier for that visibility notifier 2d well I'm just going to name this visible and we're going to use its exit screen signal we just connect it so when it exits the screen we're going to do three and that is it now we have our enemy movement and does what we want when it spawns and we've got a few paths we can go in and add some more paths if we get bored with these we can you know we can add a little bit make the pass we can make that wobbly so it looks like a more of a wobbly path when it follows all that kind of thing we could randomize the speed a little bit so it looks like it's not always exactly the same alright so in the next installment we will add these to our main we'll start spawning them over here based on a timer and we will start having them shoot at the player all right thanks for watching I'll see you next time you
Original Description
This is a complete end-to-end game development tutorial using the Godot Game Engine. We're going to be making a version of the classic game "Asteroids". We're making it as we go, so there will be bugs, mistakes, etc. - but this is how real development works, exploring possible solutions, refactoring (this means going back and changing code you already wrote). I hope you enjoy it and learn something.
Code for each part can be found here: https://github.com/kidscancode/godot_tutorials/tree/master/Space_Rocks_tutorial
Support me on Patreon: http://patreon.com/kidscancode
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from KidsCanCode · KidsCanCode · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Learning to Code with Python: Lesson 1.1 - What is Programming?
KidsCanCode
Learning to Code with Python: Lesson 1.2 - Drawing with Turtles
KidsCanCode
Learning to Code with Python: Lesson 1.3 - Variables
KidsCanCode
Learning to Code with Python: Lesson 1.4 - Loops (and more turtles!)
KidsCanCode
Learning to Code with Python: Lesson 1.5 - Saving and Running Programs
KidsCanCode
Learning to Code with Python: Lesson 1.6 - Functions
KidsCanCode
Learning to Code with Python: Lesson 1.7 - Input and Conditional Statements
KidsCanCode
Learning to Code with Python: Lesson 1.8 - Number Guessing Game
KidsCanCode
KidsCanCode - Patreon Intro Video
KidsCanCode
Learning to Code with Python: Lesson 1.9 - Rock Paper Scissors Game
KidsCanCode
Learning to Code with Python: Lesson 1.10 - Secret Codes
KidsCanCode
Learning to Code with Python: Lesson 2.1 Creating Computer Graphics
KidsCanCode
Learning to Code with Python: Lesson 2.2 Simple Animation
KidsCanCode
Learning to Code with Python: Lesson 2.3: Animating More Objects
KidsCanCode
Learning to Code with Python: Lesson 2.4: More Fun with Animation
KidsCanCode
Extra: Setting up the Atom Editor for Python
KidsCanCode
Game Development 1-1: Getting Started with Pygame
KidsCanCode
Game Development 1-2: Working with Sprites
KidsCanCode
Game Development 1-3: More About Sprites
KidsCanCode
Pygame Shmup Part 1: Player Sprite and Controls
KidsCanCode
Pygame Shmup Part 2: Enemy Sprites
KidsCanCode
Pygame Shmup Part 3: Collisions (and Bullets!)
KidsCanCode
Pygame Shmup Part 4: Adding Graphics
KidsCanCode
Pygame Shmup Part 5: Improved Collisions
KidsCanCode
Pygame Shmup Part 6: Sprite Animation
KidsCanCode
Pygame Shmup Part 7: Score (and Drawing Text)
KidsCanCode
Pygame Shmup Part 8: Sound and Music
KidsCanCode
Pygame Shmup Part 9: Shields
KidsCanCode
Pygame Shmup Part 10: Explosions
KidsCanCode
Pygame Shmup Part 11: Player Lives
KidsCanCode
Pygame Shmup Part 12: Powerups
KidsCanCode
Pygame Shmup Part 13: Powerups (part 2)
KidsCanCode
Pygame Shmup Part 14: Game Over Screen
KidsCanCode
Pygame Platformer Part 1: Setting Up
KidsCanCode
Pygame Platformer Part 2: Player Movement
KidsCanCode
Pygame Platformer Part 3: Gravity and Platforms
KidsCanCode
Pygame Platformer Part 4: Jumping
KidsCanCode
Pygame Platformer Part 5: Scrolling the Window
KidsCanCode
Pygame Platformer Part 6: Game Over
KidsCanCode
Pygame Platformer Part 7: Splash & End Screens
KidsCanCode
Pygame Platformer Part 8: Saving High Score
KidsCanCode
Pygame Platformer Part 9: Using Spritesheets
KidsCanCode
Pygame Platformer Part 10: Character Animation (part 1)
KidsCanCode
Pygame Platformer Part 11: Character Animation (part 2)
KidsCanCode
Pygame Platformer Part 12: Platform Graphics
KidsCanCode
Pygame Platformer Part 13: Improved Jumping
KidsCanCode
Pygame Platformer Part 14: Sound and Music
KidsCanCode
Pygame Platformer Part 15: Powerups
KidsCanCode
Pygame Platformer Part 16: Enemies
KidsCanCode
Pygame Platformer Part 17: Using Collision Masks
KidsCanCode
Pygame Platformer Part 18: Scrolling Background
KidsCanCode
Pygame Platformer Part 19: Wrapping Up
KidsCanCode
Gamedev In-depth Topics: 4-way vs. 8-way Movement
KidsCanCode
Gamedev In-depth Topics: Time-based vs. Frame-based Movement
KidsCanCode
Gamedev In-depth Topics: Non-integer Movement
KidsCanCode
Tile-based game Part 1: Setting up
KidsCanCode
Tile-based game Part 2: Collisions and Tilemap
KidsCanCode
Tile-based game Part 3: Smooth Movement
KidsCanCode
Tile-based game Part 4: Scrolling Map / Camera
KidsCanCode
Tile-based game Part 5: Player Graphics
KidsCanCode
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
Use a model route manifest before Dify, Cursor, and Node.js share Vector Engine
Dev.to AI
What 90 Days of Comments on AI Side Panels Taught Me About Distribution
Dev.to · AI Buddy
Claude vs ChatGPT for Small Business (2026): The Real Numbers Behind the Quiet Takeover
Medium · AI
AI Builds the Website in Minutes. So What Are You Actually Charging For?
Medium · AI
🎓
Tutor Explanation
DeepCamp AI