Tips to Create a 2.5D Game in the Godot Game Engine (tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a young student asked me how he could create something like that in Google a game with more or less 2d graphics so with character sprites but with the ability to move in space and he sent me a solution form game maker which is a 2d engine where you have some code to fake the z axis which works fine if you are making a very basic game but it's actually quite hard to fake this 3d movement in 2d because you have to essentially write custom physics rewrite all the collisions and to handle depth salting in which a 3d engine can do for you in this example I've decided to go with the 3d engine to show a potential way to implement the game here is the 3d world and we're going to see the tricks that make this little scene work some tips you can apply to your own project I'm not going to talk too much about the code because the character movement is quite similar to what you would do in 2d with a kinematic body tt speaking of which the boxes are static bodies with a collision box so you have a mesh and a collision box here for each of them and the cadet the character is a kinematic body 2d so we're relying on godot's collisions here physics engine which has a collision shape that is larger than the sprite what's most important here is that the collision box is larger than the sprite on the width and the depth but the height is not as important all that matters is that the collision shape itself is standing on the ground which is always a bit haunted place here the reason for that is that as long as the character sprite doesn't get through when you jump it doesn't get through the shape that's above it it's fine you will never see it clipping or intersecting with 3d meshes but if you make the collision box too thin like so and you play the game the sprite will intersect with the world that's the first constraint you have when you create those kinds of games in 3d is that you want to make the collision box as wide as the character and it's going to collide a bit early with the walls that's why in games that used those kinds of techniques you either had you could not directly collide with the walls in the game all you had some custom rendering or you had characters that were thin and tall so that you didn't have that large head that could intersect over the world make the character feel it's a bit far from the walls the second trick I want to share is how I'm using a sprite 3d so you can use a sprite in 3d in Godot and it works similarly to sprite in the 2d workspace you also have access to an animated sprite and can animate the sprite sheets or the characters like you would do in 2d with an animation player no problem the sprite 3d has a camera attached to it so it will always be facing the camera I were to look here you could see however I rotate the character it's always going to be facing the camera and so you want all sprites to be rotated kind of the same way in your game if I was to rotate it 45 degrees guess what would happen when I play the game you get an isometric 2.5 D game then you need to fix the controls right now there are bits of guru doesn't have automated camera facing meshes I think so if you wanted to have that you would have to code it take the Ray that comes from the camera the cameras vector and have a script on every sprite in the game that would make it always face the camera it's one line of code but it's worth noting that you don't have a checkbox to do it I believe B sites that the character script we can look at it really quickly if you've worked in 2d and made a 2-d game character you will see that the code is quite similar we calculate the direction the character is going to move on the ground by subtracting the result from the get action action stress calls on the input singleton we then normalize that vector and we calculate a velocity vector in 3d using on the x axis and the z axis the direction on the ground the reason being if I select cadet here I look at the axes you can see that the ground is made of the x and z axis and the y axis is going to go up here everything that has to do with jumping is going to happen on the y axis of our velocity vector will then use remove and slide method to move our character based on a velocity and quite important you want to set the floor normal it's a constant here say your vector pointing up for the is on floor method to work this method is going to return true or false so it's going to return true if you are standing on some ground on the floor or on some slope when the player presses the jump key it's set to space in this project we set the velocity to a fairly high value the jump falls and as long as the character is in the air it's not on the floor at least we are going to subtract a gravity multiplied by Delta by downward acceleration after we move the character if it's colliding on the floor if it touches the floor or it touches some ceiling we set the velocity back to zero the reason we do that both when we touch the floor or the ceiling is that if we don't reset it when we reach the ceiling the velocity Y will be a bit too high and the character will loads for a little while against the ceiling I can remove this statement here show you that when you're under the block here if I jump the character gets stuck for a little moment it doesn't bounce of the ceiling well if I add the statement back the character is going to bounce and fall back down pretty much instantly so that's it that's the important code in this character and the only code in this project the physics engine is handling all the collisions for us next I want to talk a bit about textures if you import a sprite by default and use it on a sprite 3d node it's going to look a little off I'm going to reset the texture I'm gonna use the texture preset let's say because when you import a sprite I think it'll be set to 2d by default it will look like that little washed out so you want to use the 3d preset and you want to go down and in the flag section of the import tab you want to false srgb you want to force the texture to use the srgb space I don't know exactly why but this fixes the colors in 3d then you might want to have fixed off a border on you can see it makes a slight difference on the sprite on the texture it removes that slight balsa effect that you get the little bleeding that gets on the outline of the character now one of the advantages of working in 3d is how you can get the shadows the ability to rotate the camera in space get quite a few advantages like these so anytime you can rotate your directional light to change how the shadows look so you could have day and night cycles you can use all the effects like and your if you go to your default environment in the game resource which you use to set we have videos on this you used to set all the special effects on the game you can have ambient occlusion as I am using in the project here as I had on if I go back in the camera view you'll see that we can also use near and far depth of field ler it's linked to you the cameras position so in the game as you move the camera the blur will move with the character I want to note one thing if I deactivate the blur and go back to the game one limitation if you are working with an orthographic camera it's sometimes by default if it's too close to the character you will start to see the meshes clipping in the game world if I take my camera here and I'm moving back towards the character going to click on that icon at the top in the toolbar to change the movement to local mode so it's using the cameras rotation and rotating the axes along the camera and so if I move my camera into the box you can see in front and play the game you will see it clipped so you want the camera to be far enough from the character to not clip into the geometry then the camera settings are quite important the cameras projection is set to orthogonal you could use perspective if you want to have a complete 3d game where you can rotate the camera or to have some perspective but if you want the game world to look 2d you all want an orthogonal projection parallel lines they will look peril on the screen it won't be projected to a vanishing point then you want to tweak the size of the camera the size parameter this is what's going to make the game world small or big it's a sort of zoom level if you want when you are using the orthographic view so you use that to zoom in and out of the game and then you have the clipping planes the near and far geometry how it's going to clip compared to the camera but moving the camera far away from the character will make it not flip in the near plane however for a far plane it will depend on the angle of your camera and the scale of the world I'm using an angle of 30 degrees on the camera so that it always looks a bit down at the world and it doesn't need to catch details that are too far in the distance so you don't have to worry about LEDs you don't have to worry about some optimization that might be a little tricky so that's how I would work on a 2-d game with some depth the main difficulty or challenge you'll face in this kind of project is rendering making everything look 2d in order to do so I invite you to look at talks and breakdowns of the art of Diablo 3 where ever used camera facing meshes with textures apply to them and they use quite a few 2d elements and you want to use art like that as much 2d art as possible in your game to make it look like a 2-d game if you're if you use 3d meshes throughout your game world unless you have really good painterly textures and very organic modeling you are most likely going to get little bit of a 3d look to it it's a matter of all direction this is beyond the scope of this tutorial but that said you can find the source code the source projects on github there's a link in the description I want to thank you kindly for watching be creative have fun and let's see one another in the next one but
Info
Channel: GDQuest
Views: 51,920
Rating: undefined out of 5
Keywords: godot 2.5d, godot 2.5d tutorial, godot 2.5d game, godot 3d engine, godot 3d tutorial, godot game engine, godot engine tutorial, game development, open source, game engine, godot engine, game editor, game programming, gamedev, godot tutorial for beginners, godot beginner tutorial, game creation, free and open source software
Id: XK5qpEmUA6w
Channel Id: undefined
Length: 12min 49sec (769 seconds)
Published: Mon Mar 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.