Space Rocks! Godot Tutorial Part 3
Skills:
AI Pair Programming80%
Key Takeaways
Continues building a Space Rocks game using Godot Game Engine, focusing on game development and design
Full Transcript
hello and welcome to part three of the space rocks video engine series in the last part we wrapped up the basics of our player ship and it's shooting and now it's time to start talking about implementing the asteroids annex asteroids that fly around the screen and will give us something to shoot at so as always there's a link below to the codes for the previous part if you want to follow along and also the code for this part if you want to see the final result of this video all right let's get started all right we're ready to start adding our asteroids so I'm going to create a new scene for them and for the route we are going to use the kinematic body 2d for these asteroids and the reason I'm going to use that is I want these asteroids when they're flying around the screen to actually bounce off of each other I want them to hit each other and look like they're solid and give the impression that we are you know flying through an asteroid belt like in the Empire Strikes Back and so I'm going to save this in the scenes called asteroid and then for the appearance we're going to add a we're just going to add a standard sprite about my favorites and just for the purposes of getting this first one going we're going to go into the art folder and pick a good image there's a lot of grey and brown asteroids various sizes I'm going to take this for one okay and there it is make sure we're keeping everything together and we're going to need a collision shape for this I think a circle is going to make the most sense collision shape we add a circle shape and we'll just drag it to a good there we go approximation of B shape of the asteroid rename this to collision all right now we just need to add a script to this to make it move around so we're going to add a script Lieut in our scripts folder asteroid okay now if you watch the video 101 video I did well basically going to make this like the little bouncing sprite that goes around the screen we're going to have a velocity which is going to be a vector - we're going to have a rotation speed that's going to be how fast the asteroid spins I want it to randomly have some bit of tumbling going on and then we're going to hear in our ready we're going to randomize so that we can pick a random value for that going to set fixed process to true we're going to set the velocity to something random I'm going to say R and range and we're just I'm just going to put some values in here for now we're going to come back and set these to a range that we like once we see how it works okay and then we're going to rotate it a random amount and this is going to be in radians so we want our rand range to be between 0 and 2pi and then our rough speed we also want to randomize so how does range to be something like 1 point negative 1 point size 1 plus s so some will be clockwise some will be can counterclockwise and now in our fixed process we're going to update the rotation we're just going to say set rotation to whatever the rotation is now plus the rotation speed times Delta and then we're going to say move a lot of three times Delta you want to move use move when you're moving a physics body the kinematic body to D or one of the other physics bodies because what moved is it tries to move the object whatever distance this is but we'll stop it's a big exit collision that's how you make your object stop when it hits a wall or whatever in our or in our case we make it stop plan and hits another it's another meteor you don't want to use set pause very much with physics bodies because it'll mess up the physics calculations and you'll get some weird results so you want to try to avoid doing that okay so let's see what we have so far we hit run we get a meteor rotating going off in a random direction with the rotation okay so that's good okay I skipped ahead a little bit since we did this in a previous video I've just added variables here to track the screen size and the extent of our texture which I'm getting in the ready function I'm just getting a viewport rec and I'm getting the texture size of the sprite and I'm dividing by two because I care about how far the edges from the center because our position is tracking the center of the sprite and then down here I'm just I've got four if statements that are just detecting where the position is and if it moves off the edge resetting its position to the opposite edge I know I said try not to use set pause but since we'll be teleporting from one slide over here to the other side over here there's not going to be any physics going on around there at least not hopefully too much so that should work pretty well let's run this real quick just so we can see there goes the meteor and when it goes off the side there we go okay so now we won't lose any of our DS so eventually we're going to want to take these images and use all of these different graphics for our asteroid go look at the sprite here this one is one of the big ones but we could also use a medium one which is that much smaller there's a small size like that and then there's even a tiny one like that of course every time we change the texture size we're going to need to change this circle because the circle is not going to match so we're going to do that because what we eventually want is when the bullet hits this big one is going to explode and split into two or maybe more smaller ones but we're not going to worry about that right now we're going to stick with this and talk about how we're going to do this collisions so it's time to make our main scene so I'm going to get new scene here and I'm going to make it just have a node as its root this is going to be main just saved in our scene folder and it's going to have as a child we're going to load one of the player nodes there alright and then we're also going to grab a few of these asteroids I just want to have again we'll do this differently once we have it all working but I want to put let's say five of these in here now because these are physics bodies they are going to collide so we need to spread these out so they do not spawn inside of each other that's going to be a problem now when we run this we should see them moving around now what's going to happen when they run into each other is they're just going to stop moving all right they're going to try to keep going at the same velocity because we're not changing their velocity any but when one of them gets in the way it's just going to kind of block the other one until they sort of slide past each other and that's not what we want that's it look good at all okay so we go back over to our script what we're going to do is after we move we're going to check and see if is colliding is true that's going to tell us this function will return true if this this body has run into another physics body if it is we want to change the velocity change the direction right of the velocity so we're going to take whatever the velocity is now and we're going to add its collision normal the normal of a collision is a vector a unit vector length of one pointing away from directly away from the surface of the collision so this is going to be pointing away from the sprite we ran into so if we look over here at the picture for a second all right if I'm coming along here and I hit this and I hit this asteroid the collision normal is going to be pointing directly away like that that's the direction that I want the velocity to be altered by so I'm going to take that and multiply it by whatever whatever the thing I ran into velocity is the magnitude of it times some bounce factor this is something we can tweak to get them just the way we want so I'm going to put that up here at the top as a thing that we can adjust we're going to export that and for the moment we're going to use one point one for that okay and so that's how we're going to adjust our velocity and let's take a look at what happens now when they bump into each other or randomness is making them not run into each other let's try another one here we go see how they bounce off of each other that's pretty good try a couple more just to be sure there we go see that was really nice but now it look doesn't look very exciting right there they're behaving the way we want them to behave doesn't look very nice so now we're just going to pretty it up a little by adding a little effect to that bounce all right so over on the asteroid you're going to add a new node called a particles to be I don't want good to be a childís right I want it to be a child of the asteroid okay this is going to be gonna call this a puff that's going to be a little puff of debris that's going to puff out there when the two of these run into each other you can see when you first add a particle node it just starts streaming out some little dust particles and that's not really what we are going to want it to do first of all let's split it at the put it on the edge so we can at least look at it the way we're going to want to see it so I'm just going to shift it over let's say another 40 40 okay 35 by 35 is going to do it okay I just want to see it somewhere near the edge of the meteor we're going to programmatically choose where it happens but for right now now there's tons and tons of settings that you can play around with for particles and they're endless fun to mess around with but a few of the things we want to change I want the lifetime to be a lot shorter this is not going to last a long time I want the time out I'm going to want these to not last very long so I'm going to change that to 0.4 and now every time it starts it's going to stop again see if I click it on clicks back off again so we're just going to pop out a little bit I'll zoom in so you can see it better okay so that's that but that's not looking right yet um we're also going to go down to explosiveness I'm going to make that 0.1 and what that's going to do is just make it more of a burst instead of a stream right okay so that's good and now a few other things we want to change here I'm going to change spread here to 180 if I don't get spread out more I'm going to change linear velocity to 50 a little bit higher beginnings gravity to zero I don't want them to fall in unique direction and I'm going to change initial and final size I'm going to the initial size five and the final size zero okay now if we try this one what it's going to look like so it looks like a burst of stuff coming out and I don't want it to look like that ring though I want it to be a little bit more randomized so I'm going to go to half extents here and I'm going to set that to 10 by 10 because that's going to make them spread out more there we go that's going to look good if i zoom back out to more like what we're going to see on the screen there we go we just have a little tough of stuff coming off and now back to our script we are going to grab that node we have a reference to it and then we want to find one of these whenever there's a collision so in the if is colliding what we're going to do is we're going to take the puffs we're going to set its global position to get to get collision pause so it sets the reason to where the collision happened so it looks like it's happened there and we're going to set emitting to true we want it to start going and because we made it lifetime short it will stop again so if we go and run our main beam we should see some little sparks when they run into each other thanks okay that will do it for part three starting to come together in the next video we will start talking about how to make the bullets destroy these meteors have the meteors be different sizes and how the meteors run into the player because right now we just fly straight through them thanks for watching and I will 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 this project 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
🎓
Tutor Explanation
DeepCamp AI