Explore Free Godot Tutorials – GameDev Academy https://gamedevacademy.org Tutorials on Game Development, Unity, Phaser and HTML5 Tue, 11 Apr 2023 19:08:53 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 https://gamedevacademy.org/wp-content/uploads/2015/09/cropped-GDA_logofinal_2015-h70-32x32.png Explore Free Godot Tutorials – GameDev Academy https://gamedevacademy.org 32 32 Unreal vs Godot – Should You Use One or the Other for Games? https://gamedevacademy.org/unreal-vs-godot/ Tue, 11 Apr 2023 08:31:27 +0000 https://gamedevacademy.org/?p=20276 Read more]]> Fact: your favorite video games are developed using game engines.

From well-known engines like Unity to lesser-known engines like Pico-8, game engines are an important facet of game development. They dictate the entire manner in which you go about it, and unsurprisingly, each engine has its own unique features. As you can imagine, picking the “right” game engine is very important when starting a game project.

In this article, we’re going to take a look at two very popular engines: Unreal Engine and Godot. We’ll be exploring both in terms of things such as versatility and popularity, and give you all the need-to-know info to decide which engine is the best for your personal situation.

Let’s get going!

What is a game engine?

Before we get too deep into this discussion topic, we do want to discuss a bit about what game engines actually are. For those just starting out, this is a good concept to wrap your mind around so you can interact with game dev jargon successfully.

A game engine, sometimes known as a game framework or game architecture, is a software development platform including settings that optimize and improve the experience of developing video games.

Game engines can facilitate the development of 2D and 3D games compatible with different import formats, allow developers to simulate physics, integrate AI, and use a sound engine to produce sounds.

Without game engines, the game development would be a lot more tedious. Instead of just working with your actual game mechanics or doing things like making cutscenes, you’d be stuck writing every backend structure. This includes things such as telling the computer how to even render your graphics. Making an engine is no small feat, and there’s a reason many engines are in-house and proprietary for AAA studios.

As such, game engines are one of the most important tools for development as they reduce the time and effort it takes to make a successful game (which believe us, still takes many, many hours).

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Versatility

As a developer, you’re free to make any type of game you wish – like 2D, 3D, AR, VR, mobile, multiplayer, and more. The game engine you choose should support the game type you wish to create, and Unreal Engine and Godot both support a wide range of games.

These include:

  • 2D. While Unreal Engine is best known for making 3D games, it can also be used to make 2D platformer games like Snake or sprite-based games. That said, Unreal Engine is definitely not the best for 2D, and can’t really be recommended. In the opposite corner, new updates to Godot 4 have significantly improved its ability to make powerful 2D games, with features such as 2D lighting, 2D light and shadow support, 2D materials, and 2D masking and clipping. Plus, Godot has a dedicated 2D engine, making it more performant in this arena (especially when it comes to physics).
  • 3D.Unreal Engine is well known for its powerful 3D game development software, with features such as pipeline integration, world-building, and simulation & effects. In comparison, while Godot does offer 3D and is powerful (with Godot 4 adding updates in this area as well), it simply can’t compare to the powerhouse that is Unreal Engine.
  • Augmented Reality (AR). There are currently no AR capabilities for Godot, whereas Unreal Engine has a high-level AR interface with features including face tracking, people occlusion, motion capture, augmented faces, and more.
  • Virtual Reality (VR). While Godot’s VR software isn’t yet up to par because of licensing issues, Unreal Engine’s VR framework is vast, allowing developers to build highly powered virtual reality apps. Unreal Engine is compatible with Oculus VR, SteamVR, Windows Mixed Reality, Samsung Gear VR, and Google VR.
  • Mobile. Both Godot and Unreal Engine have mobile capabilities. However, Unreal Engine has far more features and is compatible with Android and iOS game development.
  • Multiplayer. Godot 4 has made significant improvements to make complex multiplayer games easier for developers. The update includes improvements in scene replications and state & RSET updates. As for Unreal Engine, it also has lots of multiplayer features that are well-established, well-documented, and fairly stable.

Unreal vs Godot - Should You Use One or the Other for Games?

Coding

As a general rule of thumb, game engines tend to have one or two languages they specialize in. As such, picking the right game engine can often be tied to picking your preferred programming language as well.

In the case of Unreal Engine, there are two major choices – C++ and Blueprints Visual Scripting.

C++ is one of the most universally used and powerful programming languages out there – so you can’t go wrong with learning C++. However, and that’s a big however, it is also one of the single most difficult languages and not particularly designed for readability. Additionally, in recent years, many indie developers have moved away from C++ due to facing issues coding with it.

On the other hand, the Blueprints Visual Scripting system in Unreal is immensely powerful. With it, there’s no need to know how to code – instead you just drag and drop your functionality right onto the canvas to create logic. Thus, it’s a fantastic option for beginners who’d rather not learn tedious syntax they’ll never remember.

As for Godot, there are also two main languages here, C# and GDScript.

C# is similar to C++… except that is much more beginner-friendly. C# was designed to be a somewhat balanced language, coming with the readability of higher-level languages but still having some benefits that come only with low-level languages.

That said, Godot’s main driving force is GDScript – a scripting language developed specifically for the engine. This language, which resembles Python in some respects, is made to be easy to read and easy to use specifically for game development. That said, GDScript can’t really be used outside Godot, so learning it doesn’t benefit you if you want to go onto other platforms.

Industry Presence & Popularity

Professional game developers understand what makes a good game engine, and their use of such software can be a determining factor used to judge the competence of a software. Both Unreal Engine and Godot have made a splash in the video game industry, and both are capable of developing powerful games.

Unreal Engine is popular thanks to its high-fidelity graphics, ease of access, modularity, and just immensely powerful rendering capabilities. It’s used by both novice and expert developers, and has been used to make some of the most popular games on the market including Fortnite, Batman: Arkham City, The Matrix Awakens, and Alien: Fireteam Elite.

Likewise, Unreal Engine has been widely used even outside of games – especially when it comes to things such as film where its graphics can’t often be beaten by other software.

Godot, on the other hand, is a much younger engine. And, simply due to this youth, it’s not as established in the industry. That said – and particularly for indie developers – Godot has been quickly on the rise. Godot is also open source, which has attracted a lot of developers given the popularity of open source in general.

Regardless of its age, though, Godot has been used to create some popular games, including Lumencraft, Project Heartbeat, and Dashpong.

Unreal vs Godot - Should You Use One or the Other for Games?

Community

Game developers need a supportive community network when making a game, normally seeking support from other professionals, subreddits, YouTube channels, and more. Both Unreal and Godot have online communities offering resources for online users.

  • As an open-source project, Godot has attracted a vast community. From subreddits to a Discord chat, there’s a place for everyone in the Godot community to help each other and even contribute to the engine’s development.
  • Unreal Engine has a subreddit with over 200,000 Unreal Developers, giving information on everything you’ll ever need to know about Unreal. They also have a YouTube channel with regular updates about the game engine, tutorials, reviews, and more.
  • If you’re interested in attending in-person and online events, Unreal Engine hosts events throughout the year, designed to help fellow Unreal developers connect and share their innovations.
  • Godot also hosts various in-person and online events every year. For example, at Godot @ GDC 2023 they showcased their new games made using the Godot 4 game engine.

Both Unreal Engine and Godot also have a marketplace for assets like 3D models, textures, and systems that can be used on the engine, known as asset stores. These are largely driven by the community as well, so both have a lot to offer here.

Cost

If you’re an indie, then there’s another huge factor to consider: how much is all this going to cost you? That’s where you’re fortunate.

Unreal Engine has three licenses. With the standard license, it’s completely free to use the engine. The only catch is that once you make $1 million in revenue, you need to pay a 5% royalty fee. That said, if you do need more features, such as more developer support, Unreal also offers the Enterprise License which costs $1,500 per seat per year, or their Custom License which is quoted based on your needs.

Godot, on the other hand, is completely free. As an open-source project, there are no secret strings attached. It’s just free and will remain free far into the foreseeable future.

Tutorials & Courses

We imagine at this point, you’ve been swayed in one direction or another. So we’re going to kill two birds with one stone. First, we’re going to get you started with learning resources for both so you can jump right in. Second, we’ll give you a chance to see both engines in action by the same links. Trying both engines is the best way to figure out which one is for you!

Unreal

  • Unreal Game Development Mini-Degree, Zenva. In Zenva’s curriculum, you can start off with zero knowledge and learn Unreal Engine 5 from the ground up. You’ll master everything from the basics of the engine itself, to making portfolio-worthy projects such as FPS games, RPGs, walking simulators, and more!
  • Unreal Engine 101 – 3D Game Creation, Zenva. With this free course, you’ll learn how to get started with Unreal Engine by learning the fundamentals of manipulating game objects, as well as exploring the basics of lighting and physics and how you can incorporate these elements into gaming projects.
  • Unreal Engine 5 Beginner Tutorial – UE5 Starter Course, Unreal Sensei. This free video tutorial goes over everything needed to get started with Unreal Engine, focusing on features including nanite and lumen. This course will teach you installing Unreal, navigating its 3D viewport, creating materials and worlds, sculpting landscapes and foliage, programming using Blueprints, and more.
  • Unreal Engine Beginner Tutorial: Building Your First Game, Devslopes. This video tutorial gives you the mechanisms to build a simple game using Unreal, with the Blueprint Visual Scripting system. You’ll learn the fundamentals, including the Unreal editor itself, simple AI, events, spawning objects and effects, and the process of building games.

Godot

  • Godot 4 Game Development Mini-Degree, Zenva. This curriculum is all about giving you all the fundamentals you need to get going with Godot 4. You’ll start with the fundamentals, and then work your way to building real projects such as RTS games or RPG battle systems.
  • Godot 101 – Game Engine Foundations, Zenva. The Godot 101 course aims to teach the fundamentals of working with Godot 4, including information on how to work with Godot 4’s nodes and scenes architecture. You’ll also learn a tiny bit about getting started with GDScript.
  • Godot 4 Crash Course for Beginners – GameDev 2D Top Down Tutorial, Chris’ Tutorials. This guide teaches developers everything there is to know about the changes to Godot 4, including the tilemap tools, moving characters, and the changes to GDscript syntax.
  • Create Your First Complete 3D Game with Godot, GDQuest. This course is designed for individuals with prior coding knowledge, and takes users through the coding process from start to finish – at the end, you’ll have made your very first 3D game! Learn how to spawn monsters, make your character jump and squash, the ins and outs of animation, and much more.
  • Build a Top-Down 2D GODOT RPG in 20 Minutes, Andrew Hoffman. This video tutorial will teach you how to build a top-down 2D GODOT RPG game in just 20 minutes, including information on coding collisions, character movement, tilemaps, proper scripting, and more.

Unreal vs Godot - Should You Use One or the Other for Games?

Conclusion: Unreal vs Godot – which is better?

Let’s now turn back to our original question – should you use Unreal for your games or Godot?

The answer here is complex, and there is no one definite “right” answer. It all depends on you and your game projects. For example, if you’re making a VR game, then of course Unreal is going to be the better choice of tool. However, Godot is going to do much, much better with a 2D game, so for that Godot is the superior option.

Then again, perhaps you want the benefit of visual scripting for your 2D game, which means Unreal. Or, perhaps you just like Godot’s multiplayer features better so pick Godot for your 3D game anyway. It all comes down to personal taste and what you’re comfortable working with.

That said, it also doesn’t matter to some degree. Both engines offer a ton of resources to use, including tons of courses through which to learn and explore things.

Still, we hope this article has helped you become more informed, and we can’t wait to see the games you create with one or both engines!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Unity vs Godot – Choosing the Right Game Engine for You https://gamedevacademy.org/unity-vs-godot/ Tue, 11 Apr 2023 05:44:19 +0000 https://gamedevacademy.org/?p=20270 Read more]]> Most modern video games are developed using a game engine – which allows developers to focus on building their game rather than the tedious backend systems that run it. This makes finding a game engine that works for your project essential, since you’ll be spending quite a bit of time working with it.

With a ton of game engines available, though, how do you pick?

In this article, we’ll be exploring Unity and Godot – two powerful and popular game engines used for 2D & 3D games.

When looking for a game engine, it’s essential to assess its versatility, power, and popularity within the industry. We’ll be taking a look at several factors – such as their versatility and industry presence, and also get you learning resources so you can dive into the engine of your choice.

If you’re ready to pick your game engine, let’s get started!

What is a game engine?

Before we get started, for those new to game development, we first want to talk a bit about what a game engine is. In this way, the reason why a game engine can help you is more clear (and you can temper your ambitions by thinking you need to make your own).

A game engine, sometimes referred to as game architecture or game framework, is a software development environment complete with settings and configurations that improve and optimize the development of video games, integrating with various programming languages.

Game engines can include 2D and/or 3D graphics rendering engines that are compatible with different import formats. They will also often include a physics engine that simulates real-life properties, AI that is designed to respond to the player’s actions, and a sound engine that controls the sound effects within the game.

As stated previously, game engines are primarily designed to make your life easier. Without them, not only would you have to program your game mechanics, but instructions for your computer on how to access and play sounds, how to display your graphics, and so on. This quickly becomes a huge tedium of work – which is often why a big deal is made whenever a AAA company makes a new in-house engine; they really change everything about how a game runs in general.

To summarize, game engines are simply a powerful tool for your game development arsenal. They make sure you aren’t stuck programming every single tiny detail (unless you want to), and get to have fun with the stuff most players actually care about.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Versatility

There are a variety of different types of games that you can choose to develop, from 2D to virtual reality. A good game engine will support coders in creating a wide range of games, and both Unity and Godot do this. Here are the different types of games you can choose to develop and how Unity and Godot can support your development journey:

  • 2D. Both engines are more than capable of developing 2D games, with Unity giving its users a broad tool set. However, new updates to Godot 4 have significantly improved its ability to create 2D games, including 2D lighting, 2D materials, 2D light & shadow support, and 2D masking and clipping. It’s also worth noting that Godot offers an actual dedicated 2D engine, while Unity still technically uses its 3D engine to render 2D games. This has some performance implications for more complicated projects.
  • 3D. While Godot is capable of making 3D games, it isn’t as powerful and doesn’t have as many features as Unity. In terms of graphic fidelity, Unity is therefore the superior choice. That said, Unity is consequently the heavier-duty engine and may not work as well on older computers as Godot.
  • Augmented Reality (AR). There are currently no AR capabilities for Godot, whereas Unity has an established AR interface and has been contributing to AR output for years.
  • Virtual Reality (VR). Unity is an excellent game engine in terms of VR, as the plugins used are versatile and are able to integrate into the XR infrastructure. While VR capabilities have improved with Godot 4, export doesn’t yet work for meta quests due to licensing issues. For now, Unity is still the superior choice.
  • Mobile. Both Godot and Unity have mobile capabilities. That said, Unity perhaps offers a few more tools when it comes to the actual development process, such as the Device Simulator.
  • Multiplayer. Both platforms have multiplayer features to offer. The Godot 4 update in particular has massively improved the ability to make complex multiplayer games. The update includes improvements in scene replications, RSET, and state updates. As for Unity, with the recent release of the Unity Multiplayer Networking features, it’s easier than ever to develop multiplayer projects. In this area, both over a relatively good basis to work from.

Unity vs Godot - Choosing the Right Game Engine for You

Coding

The coding language you are most comfortable with will have a determining factor in what game engine you decide to use.

Unity uses C# for its scripting logic, which is generally considered a fairly well-balanced language to learn. This language offers some enhanced readability compared to C++, but has a plethora of advantages that other high-level languages can’t offer.

If coding plainly isn’t your thing, Unity also does offer a visual scripting option in its newest versions. This drag-and-drop approach means you don’t have to learn tedious C# syntax, but still get all the game logic you would with regular coding.

In comparison, while Godot is compatible with a few languages, its main language focuses are GDScript and C#. We’ve spoken about C# already for Unity, but GDScript is perhaps Godot’s “main” language. This Python-like language is made to be super easy to read and use with the Godot engine specifically (as it was developed by the Godot team). While this doesn’t have the versatility of C#, it does come with a variety of benefits for making games that much easier to make.

Industry Presence & Popularity

The game engines that professional developers are using is a good way to judge the versatility and usability of the software. Unity and Godot are both popular game engines used to create high-powered games that are popular on the market. However, each has different uses.

Unity is popular with AAA and indie developers alike because of its abundant resources. These resources include things like instant assets, online community assistance, Unity-provided tutorials, and intuitive tools for a variety of applications. It offers a lot of developer support along the way, and makes the coding process easier compared to other similar game engines. Plus, Unity offers tons of companion services (such as monetization for mobile games), making it a one-stop shop for many users.

There’s also the benefit that the Unity game engine is as powerful as it is popular. Thus, it’s been able to spread to a ton of other industries such as film, architecture, and so much more.

Popular games created using Unity include Hearthstone, Cities: Skylines, Rust, Ori and the Blind Forest, and the majority of mobile games.

In comparison, Godot is a lot younger than Unity and doesn’t have the same presence. However, Godot is quickly rising to become a major competitor. Godot also has an advantage that Unity does not in terms of development: it’s open source. As such, developers get ultimate control over the engine itself and, if push comes to shove, can make the engine do what it wants.

Despite its youth, Godot has been used to create many successful games including Kingdoms of the Dump, Cruelty Squad, Rogue State Revolution, and Dungeondraft.

Unity vs Godot - Choosing the Right Game Engine for You

Community

A strong and supportive community is very important when choosing a game engine, as you’ll be able to seek support from subreddits, YouTube channels, Discord chats, and whatever else there is to offer (plus, asset stores count here too). Luckily, both Unity and Godot have thriving communities offering help to new and seasoned developers.

  • Unity has a game developer convention held yearly called Unite. The event mostly focuses on how to use Unity with some YouTubers teaching engaging classes.
  • Unity also has a subreddit providing expert advice and knowledge, and a YouTube channel with tutorials from expert developers.
  • Godot also hosts many in-person and online events, such as Godot @ GDC 2023, where developers will showcase their new games made using Godot.
  • Godot helps its community with a subreddit, and has their own YouTube channel as well.
  • Godot is active in a ton of other channels such as Discord, Twitter, and so forth – all of which are viewable on their promoted Community page.

Both Unity and Godot also have an asset store – a marketplace for 3D models, textures, systems, etc. that can be used on the engine (with free and paid options). These assets are beneficial for developers who need extra assistance in design or coding, and are largely community supported.

This said, if we had to pick, we would note that Unity’s community is larger simply because of its longer-established reign as a popular game engine.

Cost

Last but certainly not least, let’s talk about money. What would using these game engines cost you?

Unity has a free plan – but there is a catch. In general, the rule of thumb is that once you’re earning $100K annually, you need to purchase a paid plan. That said, the majority of users will be fine with the free plan (so unless you become a AAA overnight, don’t worry too much about it).

This said, the free plan does come with fewer features, though this centers more so around developer support. For the most part, the free version still includes things like the platform itself, core features like visual scripting, and even the Unity Plastic SCM for version control (3 users and 5GB of storage).

The paid plans are as follows, though, if you’re interested:

  • Plus – $399 per year per seat
  • Pro – $2,040 per year per seat
  • Enterprise – Custom quotes depending on need

By comparison, since its open-source Godot is entirely free, with absolutely no strings attached. Of course, this does mean it doesn’t offer the same sort of premium services Unity does, but it can be less stressful to know there can’t be any shenanigans.

Unity vs Godot - Choosing the Right Game Engine for You

Tutorials & Courses

At this point, you’re probably leaning one way or another on whether to pick Unity or Godot. However, the best way to find out your preference is simply to try them out. So, to get you started (and demonstrate the quality of learning materials available), we’ve listed out some of our favorite resources.

Unity

  • Unity Game Development Mini-Degree, Zenva. With this curriculum, you’ll explore a variety of tools and features Unity has to offer. In addition, you’ll get the chance to build a ton of projects suitable for a professional portfolio. You’ll not only learn the fundamentals of game development, but make real games including RPGs, idle games, and FPS games.
  • Unity 101 – Game Development Foundations, Zenva. This free course teaches you the very basics of how Unity works and allows you to start playing with your first game objects. You’ll also learn skills needed to build your own games in any genre you choose.
  • How to Program in C#, Brackeys. This free YouTube course teaches you how to read, write, and understand C# coding from scratch, and lays the foundation for learning Unity.
  • C# Tutorial, Derek Banas. In this tutorial, you’ll learn how to install Visual Studio and Xamarin. You’ll then cover key programming knowledge including input, output, loops, data types, and more.
  • C# Basic Series, Allan Carlos Claudino Villa. In this free course, you’ll cover everything there is to know about C# to give you the knowledge needed to create games with Unity.

Godot

  • Godot 101 – Game Engine Foundations, Zenva. With Godot 101, you’ll learn the fundamentals of working with the Godot 4 editor, including understanding the core difference between Nodes and scenes. Plus, you’ll get experience working with both 2D and 3D objects!
  • Godot 4 Game Development Mini-Degree, Zenva. This comprehensive collection of courses gives you the knowledge needed to build cross-platform games using Godot. You’ll be given the tools needed to create 2D and 3D games including RTS games, platformers, and survival games.
  • Make Your First 2D Game with Godot: Player and Enemy, GDQuest. Learn to create your own games using Godot in this beginner tutorial series, hosted on YouTube. This course gives you an entire run-through on using Godot to program different game types, perfect for complete novices.
  • Make your first 2D platformer game In Just 10 Minutes, Eli Cuaycong. In this short tutorial, you’ll learn the basics to help you with your game development journey, including tile maps, world scene, and spritesheets.

Conclusion: Unity vs Godot – which is better?

Now we’ve covered the differences between Unity and Godot, let’s get back to the ultimate question – which game engine is better?

This entirely depends on what type of game you want to make, the game’s style and needs, and what kind of knowledge you’re bringing to the table.

For instance, for 3D, AR, or VR games, Unity is definitely the superior choice as it offers all the tools needed and the power to make those games work. However, on the opposite end of the spectrum, Godot is definitely the winner when it comes to 2D given it’s the dedicated and more performant rendering engine for this aspect.

Even then, there are exceptions even to the above! For example, a game like Paper Mario would probably work better with Unity, whereas a 3D game might work better with Godot in cases where you need to work with the engine’s code itself.

Regardless, both are truly great options, and you can’t go wrong with either. Plus, with plenty of courses available for both, they’re both easy to learn.

Regardless of your choice, we wish you the best of luck with your future games!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
How to Create your First RPG UI in Godot https://gamedevacademy.org/godot-rpg-ui-tutorial/ Fri, 07 Apr 2023 05:00:35 +0000 https://gamedevacademy.org/?p=19841 Read more]]> Fact: the global RPG market is worth billions. Also fact: it’s no longer a realm for big gaming companies, but something solo and indie game developers can pursue as well.

If you’re looking to create your own games, you should definitely take into consideration making your own RPG. RPGs present you too with the opportunity to expand your coding and game design skills – as they incorporate lots of different game mechanics. However, no RPG really works without a UI, so this can’t be neglected as you develop your ideas.

In this Godot tutorial, we’re focusing on the implementation of UI elements for your RPG game. Here, we’ll be setting up a health bar together and we’ll also style a text label in order to display the amount of gold we have in the game.

Let’s dive in!

Project Files

In order to be able to follow along with this tutorial, you’ll need to download the assets found here. You can also download a copy of the source code files for the project done in the tutorial by clicking here.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Creating the UI

Let’s start by creating the UI for our RPG game.

UI Scene

Let’s go up to Scene > New Scene:

Creating a new scene in Godot

We’re going to create a root node of ‘User Interface‘:

Select 'User Interface' for the root node

We’ll rename the node to “UI” and save the scene as “UI.tscn“:

Renaming the node to "UI"

Health Bar

Let’s right-click on our UI node and add a child node of type TextureProgress:

Adding a child node for the UI node in Godot

A TextureProgress is a bar, which can fill up a certain amount based on a given value:

TextureProgress bar in Godot

In the Inspector, we’ll drag in the image for our UI texture (UI > UI_WhiteSquare.png). into Textures > Under and Textures > Progress:

Dragging our UI texture image into the Textures' settings

We’ll also set Tint > Under to dark grey, Tint > Progress to red, and Range > Value to 50 so we can see that the progress is 50% of the way.

Enable ‘Nine Patch Stretch‘ so that the bar can be stretched to fit the size of the border:

Enabling 'Nine Patch Stretch' for the TextureProgress node in Godot

We’ll click and drag the anchor point down to the bottom left, so the health bar is snapped to the bottom left corner of the screen regardless of the screen size:

Snapping the health bar to the bottom left corner of the screen

Gold

Let’s create a new label node as a child of UI, and rename it to “GoldText”:

Creating a "GoldText" label for our UI node

Then position it above the health bar and extend it out sideways:

Positioning the GoldText node above the health bar on the screen

We’ll give it a sample text (“Gold: 500”) and align the text to the center:

Setting a sample text for our label in Godot

Sample text displaying on the screen

Custom Font

Let’s right-click on our font file (Font > Ubuntu-Regular.ttf), and click on “New Resource…“:

Adding a new font resource in Godot

… and create DynamicFont and save it as “Ubuntu-Regular.tres”:

Creating a DynamicFont in Godot

Save the new font as "Ubuntu-Regular.tres"

We’ll set the font size to 30 in the Inspector, and drag our font file (Ubuntu-Regular.ttf) into Font Data:

Setting up the new font's attributes in the Inspector

Now, let’s select the GoldText node, and assign a custom font here by dragging in the dynamic font (Ubuntu-Regular.tres) into Custom Fonts:

Assigning the dynamic custom font to the GoldText in Godot

Make sure that the anchor point of this node is also positioned at the bottom left corner of the screen:

Positionof the anchor point of the label node is at the bottom left corner of the screen

Implementing the UI

Now that our UI is all set up, let’s go back to our main scene and create a new node of type CanvasLayer:

Creating a new CanvasLayer node in Godot

Let’s drag in our UI (UI.tscn) as a child of the CanvasLayer:

Placing the UI.tscn as a child node of the CanvasLayer

UI node as a child of CanvasLayer in Godot

Our UI is now rendered on our screen:

UI rendered in Godot

UI Script

In the UI Scene, let’s go to our UI node and create a new script:

Creating a new script for our UI in Godot

Setting Up Variables

First of all, we’re going to be creating variables to get access to our UI nodes (get_node):

extends Control

onready var healthBar = get_node("HealthBar")
onready var goldText = get_node("GoldText")

Now we need to create a function for each of these variables, which will update their values.

Updating the Health Bar

Let’s update our health bar first. Note that the value of the health bar is a number between zero and 100. (0% ~ 100%):

extends Control 

onready var healthBar = get_node("HealthBar")
onready var goldText = get_node("GoldText")

# called when we take damage
func update_health_bar (curHp, maxHp):
  
  healthBar.value = (100 / maxHp) * curHp

We divided 100 by our maxHP to get the percentage value and then multiplied it by curHP to get our current health.

Updating the Text

Let’s update our gold text now. Make sure to include the text and the colon (“Gold :“) before the number:

Updating our gold text in Godot

extends Control

onready var healthBar = get_node("HealthBar")
onready var goldText = get_node("GoldText")

# called when we take damage
func update_health_bar (curHp, maxHp):
  
  healthBar.value = (100 / maxHp) * curHp


# called when our gold changes
func update_gold_text (gold):
  
  goldText.text = "Gold: " + str(gold)

Initializing The UI

Next, we need to connect this up to the actual Player node. Let’s open up our Player script:

Opening up the Player script in Godot

… and create a variable to get access to our UI node:

onready var ui = get_node("/root/MainScene/CanvasLayer/UI")

We need to initialize the UI inside of the ready() function for us to see the current values instead of the default values:

func _ready ():
  
  # initialize UI
  ui.update_health_bar(curHp, maxHp)
  ui.update_gold_text(gold)

Make sure that the UI node is placed at the top of the hierarchy as it’ll return an error otherwise. This is needed because Godot initializes and updates all their nodes from top to bottom:

Placing the CanvasLayer at the top of the hierarchy in Godot

The UI node must be placed above the Player node in order for the player script to access it.

Updating UI Elements

Finally, we have to update our UI values as we play. For that, let’s get our UI node to update the HP bar inside take_damage function:

func take_damage (damageToTake):
  
  curHp -= damageToTake
  ui.update_health_bar(curHp, maxHp)
  
  if curHp <= 0:
    die()

We also need to update the gold text inside give_gold function:

func give_gold (amount):
  
  gold += amount
  ui.update_gold_text(gold)

Now if we press play, you can see that our health starts to go down if we get attacked, and our gold goes up each time we collect a coin as expected:

UI elements updating correctly in Godot

Conclusion

Well done on completing this tutorial!

Here, you’ve learned how to implement the UI for your RPG game in Godot, something you can surely expand upon and also use in other game projects as well. This UI is also useable for any kind of subgenre you want to pursue as well – whether you want to go for an action RPG like we did or something more traditional and turn-based.

However, there’s a lot more to expand upon here even in the realm of UIs! Perhaps you want to create a second bar for mana, add a frame to your health bar, or even change the health bar’s shape entirely. There are endless possibilities even in this realm – in addition to learning tons of other core mechanics!

We hope that you have fun as you continue developing your games and wish you the best of luck in your future projects!

Want to learn more about RPGs in Godot? Try our complete Develop a 3D Action RPG with Godot 3 course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Intro to Strategy Tile Management Systems for Godot Games https://gamedevacademy.org/godot-tile-management-tutorial/ Thu, 06 Apr 2023 10:33:22 +0000 https://gamedevacademy.org/?p=19823 Read more]]> Strategy games are still one of the most popular genres – testing players’ decision-making abilities to achieve goals with limited resources.

However, they can involve some really taxing mechanics for developers as well to create, let alone balance to make a challenging but fun game. That said, with a smaller map and only a handful of different types of buildings or resources, we can already familiarize ourselves with the process of developing city-builders, which are a great start for any skill level!

In this Godot tutorial, you’ll learn how to map all the tiles of your grid in a way to know which ones have buildings on them and which are available to be selected next. We’ll also show you how to highlight tiles that are ready to receive buildings on them in each turn!

That said, let’s get started!

Project Files

Before you begin, note that some basic Godot experience is required, including knowledge of how to set up your project and create your tile map for the game. Aside from that, you can download a copy of the source code files for the project done in this tutorial here.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Tile Script

To start, go over to the Tile scene and select the root node:

Selecting the Tile root node in Godot

Create a new script on our tile in the inspector:

Creating a new script for the Tile object in Godot

Let’s save the script as “Tile.gd”.

Creating Variables

In this script, we’ll create a boolean called ‘startTile’ using the keyword export. The export keyword allows us to set the value of the variable in the Inspector:

extends Area2D

export var startTile : bool = false

We will select the tile in the middle and set the ‘startTile‘ to be true (ticked):

Checking the startTile box in the Inspector tab in Godot

We need two more boolean variables to check whether or not this tile has a building on it, and also to check if we can place buildings on the selected tile:

extends Area2D

export var startTile : bool = false

var hasBuilding : bool = false
var canPlaceBuilding : bool = false

Functions Set Up

Now, we need to load two sprite components: one for highlighting the tiles, and one for building icons as follows.

extends Area2D

export var startTile : bool = false

var hasBuilding : bool = false
var canPlaceBuilding : bool = false

# components
onready var highlight : Sprite = get_node("Highlight")
onready var buildingIcon : Sprite = get_node("BuildingIcon")

The function below adds the current node to the “Tiles” group as soon as it appears in the scene tree:

func _ready ():
  
  add_to_group("Tiles")

Next, we’re going to create a toggle function that is going to be called whenever we want to enable/disable the Highlight. This will be used to check whether or not we can build on our tile:

func toggle_highlight (toggle):
  
  highlight.visible = toggle
  canPlaceBuilding = toggle

When we click on the tile, we will send over the Sprite to be displayed in our BuildingIcon:

func place_building (buildingTexture):
  
  hasBuilding = true
  buildingIcon.texture = buildingTexture

Detecting Clicks on the Tiles

We need also to add a signal to detect when we have clicked on the tile. With the “Tile” node selected, go to the Inspector and click on the Node panel:

Adding a signal to our Tile node in Godot

Let’s double-click on Input_event, select the “Tile“, and click on “Connect“:

Connecting the Input_event signal to the Tile node in Godot

With this, a new function has been created inside our Tile script:

extends Area2D

export var startTile : bool = false

var hasBuilding : bool = false
var canPlaceBuilding : bool = false

# components
onready var highlight : Sprite = get_node("Highlight")
onready var buildingIcon : Sprite = get_node("BuildingIcon")

func _ready ():
  add_to_group("Tiles")

func toggle_highlight (toggle):
  highlight.visible = toggle
  canPlaceBuilding = toggle
 
func place_building (buildingTexture):
  hasBuilding = true
  buildingIcon.texture = buildingTexture

func _on_Tile_input_event(viewport, event, shape_idx):
  pass # Replace with function body.

Scripting the Map

Our next step is to do the map script. The map script is going to be managing all of the tiles in our scene. It’s going to be managing tile replacement and tile highlighting.

Let’s create a new script on the “Tiles” node:

Selecting the Tiles in the MainScene in Godot

Creating a new script for the Tiles node in Godot

We’ll save the script as “Map.gd“:

Name the script "Map.gd"

First of all, we’re going to have an array for all the tiles, another for those tiles that have the buildings, and a float for the size of each tile:

extends Node

var allTiles : Array
var tilesWithBuildings : Array
var tileSize : float = 64.0

For information about Arrays, visit the documentation: https://docs.godotengine.org/en/stable/classes/class_array.html

Getting Tile at Given Position

We will now create a function to check whether there is a tile at a certain position on the grid and if so, it also checks if there’s no building on that tile. If both conditions are true, it will return that tile to us. Otherwise, we’ll return nothing (null):

extends Node

var allTiles : Array
var tilesWithBuildings : Array
var tileSize : float = 64.0

func get_tile_at_position (position):
  
  for x in range(allTiles.size()):
    if allTiles[x].position == position and allTiles[x].hasBuilding == false:
      return allTiles[x]  
      
  return null

Our next function will be called to disable every tile highlight, as we don’t want to see the highlights anymore once we’ve placed our buildings:

func disable_tile_highlights ():
  
  for x in range(allTiles.size()):
    allTiles[x].toggle_highlight(false)

Highlighting the Tiles

Following, we need to implement the main function for this script, which will be responsible for highlighting all the tiles we can place our building on:

func highlight_available_tiles ():

The function will loop through each of the tiles in the ‘tilesWithBuildings‘ array:

func highlight_available_tiles ():
  
  for x in range(tilesWithBuildings.size()):

…and check to see if the north, south, west, and east tiles can have a building placed on them. For that, we need to get those tiles relative to our selected tile position:

func highlight_available_tiles ():
  
  for x in range(tilesWithBuildings.size()):
    
    var northTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(0, tileSize))
    var southTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(0, -tileSize))
    var eastTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(tileSize, 0))
    var westTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(-tileSize, 0))

And then it is going to toggle/highlight the tiles:

func highlight_available_tiles ():
  
  for x in range(tilesWithBuildings.size()):
    
    var northTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(0, tileSize))
    var southTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(0, -tileSize))
    var eastTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(tileSize, 0))
    var westTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(-tileSize, 0))
    
    if northTile != null:
      northTile.toggle_highlight(true)
    if southTile != null:
      southTile.toggle_highlight(true)
    if eastTile != null:
      eastTile.toggle_highlight(true)
    if westTile != null:
      westTile.toggle_highlight(true)

And that is our map script all set:

extends Node

var allTiles : Array
var tilesWithBuildings : Array
var tileSize : float = 64.0

func get_tile_at_position (position):
  
  for x in range(allTiles.size()):
    if allTiles[x].position == position and allTiles[x].hasBuilding == false:
      return allTiles[x]  
      
  return null

func disable_tile_highlights ():
  
  for x in range(allTiles.size()):
    allTiles[x].toggle_highlight(false)
    
    
func highlight_available_tiles ():
  
  for x in range(tilesWithBuildings.size()):
    
    var northTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(0, tileSize))
    var southTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(0, -tileSize))
    var eastTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(tileSize, 0))
    var westTile = get_tile_at_position(tilesWithBuildings[x].position + Vector2(-tileSize, 0))
    
    if northTile != null:
      northTile.toggle_highlight(true)
    if southTile != null:
      southTile.toggle_highlight(true)
    if eastTile != null:
      eastTile.toggle_highlight(true)
    if westTile != null:
      westTile.toggle_highlight(true)

Now you’re ready to start placing the buildings of your game on top of the available tiles as you like!

Conclusion

Congratulations on finishing up the tutorial!

You’ve learned a lot about using a tile-based strategy system in Godot, including how to know which ones already have buildings, and how to highlight empty neighbor tiles. With the tile management implementation covered in this tutorial, we’ve tackled key components for many other sorts of strategy games as well!

From here, you can continue on developing different types of buildings you want to have for your game and customize each’s impact on resource generation. You can even move to bigger maps or create personalized ones! Make sure to use all your creativity moving forward and best of luck with your future Godot games!

Want to learn more about strategy games? Try our complete Construct a Strategy Game with Godot 3 course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
A Guide to Adding Bullets for FPS Godot Games https://gamedevacademy.org/godot-bullet-fps-tutorial/ Thu, 06 Apr 2023 09:59:03 +0000 https://gamedevacademy.org/?p=19756 Read more]]> The first-person shooter (FPS) genre of video games is one of the most popular among players – with huge franchises like Call of Duty, HaloApex Legends, and many others.

While FPS games have a lot of different features that could be covered, there is one mechanic that stands above the rest: shooting. Even in a versatile environment with tons of different gun types, implementing the shooting of the bullets looks pretty much the same.

With that in mind, we’ve prepared this Godot tutorial where we’re going over the entire process of creating the bullet object and setting up its properties in the game engine. We’ll also cover the scripting of the projection of the bullets out of the gun being used in the game.

If you’re ready, let’s get started!

Project Files

You can download a copy of the source code files (including the assets) for the project done in this tutorial here.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Creating The Bullet

We’re going to start by scripting the ability for our player to shoot. For that, let’s create a new scene and save it as “Bullet.tscn”:

Creating a new scene in Godot

Here, we’re going to create the bullet prefab that we’ll be spawning at the muzzle. Create a new root node of type Area, by clicking on ‘Other Node‘ and searching for “Area”:

Creating the bullet prefab by adding an Area root node in Godot

Area is a physics node that won’t actually collide with other objects, but it can detect collisions as something goes through its collider. This is useful for bullets as they don’t need to bounce off or collide with anything, we just need it to detect when it has entered another object:

Renaming our Area node to "Bullet" in Godot

Rename this node to “Bullet”, and drag the bullet model (Models > Weapon > ammo_pistol.obj) into the scene as a child node of Bullet:

Dragging the bullet model as a child of our Bullet node in Godot

Note that the “ammo_pistol.obj” asset we’re using here can be found in the project files link above.

In the inspector, set the Transform > Translation to (0, 0, 0) to center it in the scene and set the Scale to (10, 10, 10). Lastly, set the rotation to (90, 0, 0) so it is facing forward, not upward:

Setting up the bullet model in Godot

We’ll now add another child node (CTRL+A) of type CollisionShape to the root node Bullet:

Adding a CollisionShape node to our Bullet in Godot

Set the collider shape to ‘Capsule‘ in the Inspector. Then, click on the text “Capsule” to view more options and set the radius to 0.03 and the height to 0.06:

Setting up the collider's shape, radius, and height in Godot

Adding a Timer

We need to add just one more component (CTRL+A), which is a Timer, again as a child node of Bullet:

Adding a Timer as child node of Bullet in Godot

Timer is a node that waits for a given time (1 sec by default) and then emits a signal. A signal in Godot refers to an event that a node can call out once it meets a certain condition.

In the inspector, you can choose the Node tab and see the list of signals available:

Available signals for the Timer node in Godot

Back to the Inspector panel, let’s set the wait time to 5 and enable ‘Autostart’.  This will allow the timer to automatically start as soon as the game starts:

Setting up the Timer in Godot

Next, select the root node (Bullet) and create a new script by going to Script > [empty] > New Script:

Creating a new script in Godot

First of all, we are going to create variables for the speed and damage of our bullet as follows:

extends Area

var speed : float = 30.0
var damage : int = 1

To move the bullet forward, we can multiply the global transform on the z-axis (global_transform.basis.z) by speed and apply it directly on translation within func_process(). Note that delta is multiplied here to convert it from 30 units per frame to 30 units per second:

extends Area

var speed : float = 30.0
var damage : int = 1

func _process(delta):
  
  translation += global_transform.basis.z * speed * delta

Now we need to create another function that destroys the bullet whenever the bullet either runs out of the timer or hits an object. For this, we can use queue_free() which destroys the node:

func destroy ():
  
  queue_free()

Save the script. Go back to the Timer node, open up the Node panel, and double-click on the timeout() signal. It will ask us to connect a signal to a method.

In the Receiver Method input field, type in the name of the function to call (i.e. “destroy”) and hit ‘Connect’:

Connecting the Timer node to the destroy function

Our script now has this little green mark on the left which signifies that this function is connected to a signal. This function will be called once a signal is emitted:

The destroy function is now connected to a signal

Detecting An Enemy

Following, we need to be able to detect when the bullet enters another collider. Select the root node (Bullet) and open up the Node panel.

Double-click on ‘body_entered‘ and hit ‘Connect‘:

Detecting when the bullet collides with another object in Godot

We’re going to check if the object that the bullet collided with is an enemy (by checking if the object has a method called “take_damage“), and if true, we will call the “take_damage” function and send over the damage value:

func _on_Bullet_body_entered(body):
  
  if body.has_method("take_damage"):
    body.take_damage(damage)
    destroy()

Shooting Bullets

Let us now make it so that we can shoot the bullet from the game’s weapon.

Open up the player script file (Player.gd) and create a new variable to get a reference of the bullet scene:

onready var bulletScene = load("res://Bullet.tscn")

Then we need to create a function that will be called whenever we press down on the left mouse button:

func shoot ():

In this function, we’ll create a new bullet scene node using bulletScene.instance() in a variable called “bullet”:

func shoot ():
  
  var bullet = bulletScene.instance()

Then we need to give it a parent node so it can actually exist in our main scene. We can do this by using .add_child() function:

func shoot ():
  
  var bullet = bulletScene.instance()
  get_node("/root/MainScene").add_child(bullet)

Now we need to position it and orientate it where the muzzle is at:

func shoot ():
  
  var bullet = bulletScene.instance()
  get_node("/root/MainScene").add_child(bullet)
  
  bullet.global_transform = muzzle.global_transform

We have to subtract one from our ammo as well:

func shoot ():
  
  var bullet = bulletScene.instance()
  get_node("/root/MainScene").add_child(bullet)
  
  bullet.global_transform = muzzle.global_transform
  
  ammo -= 1

Finally, we need to call the shoot function whenever we press the shoot button. We will put it inside _process() as we need to check if the shoot button is pressed every frame. Also, ensure that the ammo is greater than 0:

func _process(delta):
  
  # check to see if we have shot
  if Input.is_action_just_pressed("shoot") and ammo > 0:
    shoot()

Note that the muzzle node should be facing the correct direction. If it’s facing the wrong direction, rotate it 180 degrees on the y-axis:

Rotate the muzzle node if facing the wrong way

Save and hit Play. We’re now able to shoot bullets from our gun:

Shooting bullets from our gun in Godot

Conclusion

Well done on completing this tutorial!

For those looking to build their own FPS, this is a huge step already! You can now shoot bullets from any weapon of your choice in your Godot game – with systems that make customizing your bullet assets easy!

FPS games make great projects for beginners and experience developers alike – but there’s more to do. Expanding your project further, you can design the game environment and the player’s choice of weapons as you see fit, apart from being able to add interactable pickup items and coding the enemy AI as you’d like. There are many more directions to go, but with the core shooting mechanics done you’re on the path to success!

We wish you the best of luck in your game development journey!

Want to learn more about FPS games in Godot? Try our complete Build a First-Person Shooter with Godot 3 course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
How to Create Your First Player Character in Godot https://gamedevacademy.org/player-character-godot-tutorial/ Thu, 06 Apr 2023 09:14:51 +0000 https://gamedevacademy.org/?p=19693 Read more]]> Every game has its unique, core mechanics, but one thing they all share in common is the player character.

Whether first-person or third-person, designing the movement and behavior of the player is one of the first processes that we need to go through when creating games. This is important as it’s what characterizes how the players are expected to interact with the objects and obstacles of the game. Thus, knowing how to create players is a core skill for game development that cannot be skipped!

In this tutorial, we’ll cover the creation of a player character in Godot from the start – ranging from how to create the player node and add it to the game scene to how to configure the player’s sprite and set up the properties of its collider component.

All that said, let’s dive in!

Project Files

You can download a copy of the final source code files for the project done in this tutorial here.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Creating the Player Sprite

Importing assets

After having created a new project in Godot, you first have to download the project assets available here to your computer.

Next, select and right-click the root folder in FileSystem, then go to ‘Open in File Manager‘:

Right-click on the root folder of the project in Godot and go to Open in File Manager option

This will open up a window with the files of our project. Now, with another window open with the assets you’ve downloaded from the link above, drag and drop the Sprites folder into the project folder:

Drag and drop the assets into the project folder

Or simply copy and paste them over so that they appear amongst the files of our project:

Importing assets to our project in Godot

Creating a Node to be our Player

To create our player, let’s click on ‘Scene’ and then ‘New Scene‘:

Click on Scene then 'New scene' to create our player in Godot

Select the ‘Other Node‘ option and search for “KinematicBody2D” in the ‘Create New Node’ window:

Search for KinematicBody2D when creating a new scene in Godot

Choose the ‘KinematicBody2D’ node and hit ‘Create’. The new node is now visible in the Scene window. Rename it to ‘Player‘ by double-clicking on it:

Rename the scene to Player

Adding a Sprite to the Player Node

Following, double-click the Sprites folder in the FileSystem to open it. Select the ‘Player_Idle‘ file and drag it into the viewport:

Drag the Player_Idle image to the viewport in Godot

This creates a new node as a child of the Player node:

Player_Idle is now a child node of the Player scene

In the inspector, go to Transform then click on ‘Position’. Set both x and y to 0:

Setting the position of the sprite to be the origin

The sprite is now centered in the origin (0, 0). Hit Ctrl+S to save the scene:

Sprite in origin position in Godot

Let’s also rename the sprite from ‘Player_Idle’ to ‘Sprite‘.

Adding a Collider to our Player

You’ll note that we’re having a node configuration warning next to our Player scene icon. It says that we need to add a collision child to define the shape of our KinematicBody node. To do that, right-click on the Player, and go ‘Add Child Node‘:

Adding a child node to our Player scene in Godot

Double-click on ‘CollisionShape2D‘ to create it:

Double-click on CollisionShape2D to create a new collision node

Go to Inspector and click on the arrow next to ‘Shape‘. Then select ‘New RectangleShape2D‘ as follows:

Setting up the collider node in Godot

To change the size of the collider, drag the red dots around to adjust the size so that it aligns with the whole sprite:

Adjusting the size of the collider shape in GodotCollider shape correctly adjusted to include the whole sprite size in Godot

Bringing the Player to the MainScene

At last, click on ‘MainScene‘. Go to FileSystem and drag the ‘Player.tscn‘ into the main scene:

Drag the Player.tscn into the main scene in Godot

Save the scene and click on the ‘Play‘ button:

Click on Play to run our scene in Godot

You’ll see that our player shows up in the game window:

Running our player scene in Godot

Scripting our Player in Godot

Let us now start scripting our player sprite.

Go to Project then click on ‘Project Settings…‘, and go over to the Input Map tab:

Project settings menu in Godot

Creating New Actions

We can create new actions for our sprite by adding in some new keys.

Write ‘move_left‘, ‘move_right‘ and ‘jump‘ then click on ‘Add‘ after each addition to include them to the list:

Adding action keys in Godot

We now need to assign each action a unique key. Simply click on the ‘+‘ button next to each action and press the relevant key on your keyboard:

Assigning a key to the added actions in Godot

In this tutorial, we’re going to use the left and right keys to move to the left and to the right, and the up key to jump. After confirming your choices, you can close the project settings window.

With the Player node selected, go to the Script tab in the Inspector panel. Expand it and click on ‘[empty]’. Then select ‘New Script‘ in the dropdown:

Creating a new script for our Player node in Godot

Hit the ‘Create‘ button:

Creating a new script in Godot

This will automatically open up a Scripting Interface as follows:

Script interface in Godot

Declaring Variables

A variable is basically a container that can hold data. The value may change depending on conditions or on commands passed to the program. To create our first variable, type ‘var‘ and then enter a variable name. After that, we can give it an initial value of zero by entering ‘ = 0‘:

extends KinematicBody2D

var score = 0

So now the score variable has a data type of int. You can also add a type hint with a colon (:) after the name to keep it as an integer, which is a whole number:

extends KinematicBody2D

var score : int = 0

You can also set a different data type, such as Vector2 or Sprite. Vector2 holds two numeric values that represent the x, and y coordinates of a point:

extends KinematicBody2D

var score : int = 0

var speed : int = 200
var jumpForce : int = 600
var gravity : int = 800

var vel : Vector2 = Vector2()

var sprite : Sprite = $Sprite

Note that the dollar sign ($) operator is used in front of Sprite. This basically tells the script to look through all of the children nodes and find the node of whatever type is defined after the $, which is Sprite in this case.

The alternate syntax to the dollar sign ($) operator is to use the get_node function. Simply replace $Sprite with get_node(“Sprite”):

var sprite : Sprite = get_node("Sprite")

We can also add a keyword called ‘onready‘ before ‘var’ to make sure the asset is ready when the scene loads:

onready var sprite : Sprite = get_node("Sprite")

This delays the initialization of the variable until the node of Sprite is found.

Moving the Player

Next, we will implement the ability for the player to move around and jump. First, we need to apply gravity. This is going to be done inside of a function called _physics_process():

func _physics_process(delta):

This is a built-in function of Godot, which gets called 60 times a second to process physics. First, we want to set out velocity on the x value to 0 as follows:

func _physics_process(delta):

  vel.x = 0

Then we will check our movement inputs, that is, if the Input system detects ‘move_left’ action:

func _physics_process(delta):

  vel.x = 0

  #movement inputs
  if Input.is_action_pressed("move_left"):

Our velocity on the x should be equal to negative ‘speed’ when we press the “move_left” button, and positive ‘speed’ when we press “move_right”:

func _physics_process(delta):

  vel.x = 0

  #movement inputs
  if Input.is_action_pressed("move_left"):
     vel.x -= speed
  if Input.is_action_pressed("move_right"):
     vel.x += speed

When moving a KinematicBody2D, you should not set its position property directly. Rather you should use the move_and_collide() or move_and_slide() methods. (*Note that these methods should be used within the _physics_process() callback.)

The move_and_slide() method moves the body along a given vector, and if the body collides with another, it will slide along the other body. This is especially useful in platformers or top-down games.

To use the move_and_slide(), we need first to send over the velocity and the direction in which the floor is pointing. Since the ground will be below us, this would be Vector2.Up:

func _physics_process(delta):

  vel.x = 0

  #movement inputs
  if Input.is_action_pressed("move_left"):
     vel.x -= speed
  if Input.is_action_pressed("move_right"):
     vel.x += speed

  #applying the velocity
  move_and_slide(vel, Vector2.UP)

Flipping the Sprite

Now, we can assign it to our velocity and check which direction our player sprite should be facing:

func _physics_process(delta):

  vel.x = 0

  #movement inputs
  if Input.is_action_pressed("move_left"):
     vel.x -= speed
  if Input.is_action_pressed("move_right"):
     vel.x += speed

  #applying the velocity
  vel = move_and_slide(vel, Vector2.UP)

  #sprite direction
  if vel.x < 0:
     sprite.flip_h = true
  elif vel.x > 0:
     sprite.flip_h = false

Save the script and press Play:

Moving the sprite to the right in GodotMoving the sprite to the left in Godot

You can now move the Player horizontally with arrow keys. The sprite will flip as the moving direction changes.

Applying Gravity

To implement gravity is pretty straightforward, we can simply add it directly onto our y velocity:

func _physics_process(delta):

  vel.x = 0

  #movement inputs
  if Input.is_action_pressed("move_left"):
     vel.x -= speed
  if Input.is_action_pressed("move_right"):
     vel.x += speed

  #applying the velocity
  vel = move_and_slide(vel, Vector2.UP)

  #gravity
  vel.y += gravity * delta

  #sprite direction
  if vel.x < 0:
     sprite.flip_h = true
  elif vel.x > 0:
     sprite.flip_h = false

When you add/subtract from the velocity, it needs to be multiplied by delta so that it accelerates at the correct speed:

#gravity

vel.y += gravity * delta

Jump Input

We need to check if the ‘jump’ key is detected, and we also need to check if the player is on the floor:

#jump input
if Input.is_action_just_pressed("jump") and is_on_floor():

We then want to apply the jump force in the opposite direction of gravity:

#jump input
if Input.is_action_just_pressed("jump") and is_on_floor():
  vel.y -= jumpForce

Make sure you have saved the script:

extends KinematicBody2D 
 
var score : int = 0 
 
var speed : int = 200 
var jumpForce : int = 600 
var gravity : int = 800 
 
var vel : Vector2 = Vector2()
 
onready var sprite : Sprite = get_node("Sprite")

func _physics_process(delta):
  
  vel.x = 0
  
  #movement inputs
  if Input.is_action_pressed("move_left"):
    vel.x -= speed
  if Input.is_action_pressed("move_right"):
    vel.x += speed
  
  #applying the velocity
  vel = move_and_slide(vel, Vector2.UP)
  
  #gravity
  vel.y += gravity * delta
  
  #jump input
  if Input.is_action_just_pressed("jump") and is_on_floor():
    vel.y -= jumpForce
    
  #sprite direction
  if vel.x < 0:
    sprite.flip_h = true
  elif vel.x > 0:
    sprite.flip_h = false

* Note that if you press the play button now, the character will simply fall. That happens because there’s no ground for the player to interact with, as we’re not implementing it in this tutorial. You can think of this as a challenge for yourself!

Conclusion

Well done on completing this tutorial on how to create a player with Godot!

Although there’s much to expand here, you’ve already learned how to script your player in Godot and how to set up the player’s sprite and kinematic properties so it behaves as desired! You can now move on to coming up with your game’s level style and structure, besides some enemy logic or coin collection to make your game exciting.

Godot is also a great choice for beginners – as its node-based user interface makes it easy to create games while also facilitating access and project organization. Plus, the engine is open source and has a strong community backing the project, so there are constant updates and new features being released all the time.

We wish you all the best of luck with your game projects, and that you continue learning more each day!

Further Resources

Would you like to see more on Godot? Check out our recommendations to help you on your journey below:

Want to learn more about developing in Godot? Try our complete Godot 3 Game Development for Beginners course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Complete Guide to GDScript – Godot’s Scripting Language https://gamedevacademy.org/complete-gdscript-godot-tutorial/ Thu, 06 Apr 2023 06:21:05 +0000 https://gamedevacademy.org/?p=20233 Read more]]> What is the best programming language for Godot?

With the release of Godot 4, more developers than ever before are flocking to learn this free and open-source engine. However, many come in not knowing what programming language they need to use. While C# is an option (for those familiar with Unity), GDScript is by far the go-to when it comes to scripting in Godot.

What is GDScript, though, and how does it work? In this article, we’re going to cover the fundamentals of GDScript so you can start tackling your Godot game projects with finesse.

If you’re ready, let’s get started!

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Introduction to GDScript

Welcome to the world of GDScript! In this section, you’ll learn what GDScript is, why you should use it, and how to set up your development environment so you can start writing code right away.

What is GDScript?

GDScript is a scripting language that was specifically designed for the game engine Godot. It’s a high-level language, which means it’s easy to read and write compared to lower-level languages like C++. And best of all, it’s designed with game development in mind, so it has features that make game development faster and easier.

Benefits of using GDScript

Here are a few reasons why GDScript is a great choice for game development:

  • It’s easy to learn and use, even for those who are new to programming
  • It’s optimized for game development, so you can write code faster and more efficiently
  • It integrates well with the Godot engine, making it a great choice for game development with Godot

Setting up the development environment

To start using GDScript, you’ll need to download and install the Godot game engine. You can download it for free from the Godot website. Once you have Godot installed, you’re ready to start writing GDScript code!

In the next section, we’ll dive into the basics of GDScript and start writing some code. Let’s get started!

2D Platformer made with Godot 4

Variables and Data Types

In this section, you’ll learn how to store and manipulate data in GDScript. You’ll learn about variables and different data types, and how to declare and initialize them.

Introduction to Variables

Variables are containers that store values in your code. Think of them like little containers that hold data that you can use and manipulate in your code. For example, you can store a player’s name in a variable so that you can use it throughout your game.

Declaring and Initializing Variables

To use a variable, you first have to declare it. You do this by giving it a name and specifying what type of data it will store. Here’s an example of declaring a variable in GDScript:

var player_name: String

In this example, we declared a variable named “player_name” that will store a string value. To initialize a variable, you give it a value when you declare it like this:

var player_name: String = "John Doe"

Data Types in GDScript

In GDScript, there are several data types that you can use to store different types of data. Here are the most common data types in GDScript:

    • Integer: Whole numbers, such as 1, 2, 3, etc.
var score: int = 10
    • Float: Numbers with decimal places, such as 1.5, 2.7, etc.
var price: float = 19.99
    • String: Text values, such as “hello”, “goodbye”, etc.
var player_name: String = "John Doe"
    • Boolean: A value that can either be “true” or “false”.
var game_over: bool = false
    • Array: A collection of values that can be of any data type.
var players: Array = [ "John Doe", "Jane Doe", "Jim Doe" ]
    • Dictionary: A collection of key-value pairs where each key is unique.
var player_scores: Dictionary = { "John Doe": 10, "Jane Doe": 20, "Jim Doe": 30 }

In the next section, we’ll learn about operators and expressions, which are used to manipulate data in your code.

Real-time strategy game made with Godot 4

Operators and Expressions

In this section, you’ll learn how to perform operations and manipulate data using operators and expressions in GDScript. We’ll cover different types of operators and how to use them in your code.

Arithmetic Operators

Arithmetic operators are used to perform basic arithmetic operations like addition, subtraction, multiplication, division, and more. Here are the most common arithmetic operators in GDScript:

    • +: Addition operator, used to add two values together.
var result = 2 + 2 # result will be 4
    • -: Subtraction operator, used to subtract one value from another.
var result = 5 - 2 # result will be 3
    • *: Multiplication operator, used to multiply two values.
var result = 2 * 2 # result will be 4
    • /: Division operator, used to divide one value by another.
var result = 4 / 2 # result will be 2
    • %: Modulus operator, used to find the remainder of a division operation.
var result = 7 % 3 # result will be 1

Assignment Operators

Assignment operators are used to assign values to variables. Here are the most common assignment operators in GDScript:

    • =: Simple assignment operator, used to assign a value to a variable.
var score = 10
    • +=: Addition assignment operator, used to add a value to a variable and then assign the result back to the same variable.
var score = 10
score += 5 # score will now be 15
    • -=: Subtraction assignment operator, used to subtract a value from a variable and then assign the result back to the same variable.
var score = 10
score -= 5 # score will now be 5
    • *=: Multiplication assignment operator, used to multiply a value with a variable and then assign the result back to the same variable.
var score = 10
score *= 2 # score will now be 20
    • /=: Division assignment operator, used to divide a value with a variable and then assign the result back to the same variable.
var score = 10
score /= 2 # score will now be 5

Comparison Operators

Comparison operators are used to compare two values and return a boolean value based on the comparison result. Here are the most common comparison operators in GDScript:

    • ==: Equality operator, used to check if two values are equal.
var result = 2 == 2 # result will be true
    • !=: Inequality operator, used to check if two values are not equal.
var result = 2 != 2 # result will be false
    • <: Less than operator, used to check if one value is less than another.
var result = 2 < 3 # result will be true
    • >: Greater than operator, used to check if one value is greater than another.
var result = 2 > 3 # result will be false
    • <=: Less than or equal to operator, used to check if one value is less than or equal to another.
var result = 2 <= 2 # result will be true
    • >=: Greater than or equal to operator, used to check if one value is greater than or equal to another.
var result = 2 >= 3 # result will be false

Logical Operators

Logical operators are used to perform operations on boolean values and return a boolean result. Here are the most common logical operators in GDScript:

    • and: Logical and operator, used to combine two boolean values and returns true only if both values are true.
var result = true and true # result will be true
    • or: Logical or operator, used to combine two boolean values and returns true if at least one value is true.
var result = false or true # result will be true
    • not: Logical not operator, used to negate a boolean value and returns the opposite value.
var result = not false # result will be true

3D Platformer made with Godot 4

Control Flow Statements

Control flow statements allow you to control the flow of execution of your code based on certain conditions. Here are the most common control flow statements in GDScript.

If Statement

The if statement allows you to execute a block of code only if a certain condition is met. Here’s an example:

if 2 > 1:
  print("2 is greater than 1")
# Output: 2 is greater than 1

If-Else Statement

The if-else statement allows you to execute a block of code if a certain condition is met, and another block of code if the condition is not met. Here’s an example:

if 2 < 1:
  print("2 is less than 1")
else:
  print("2 is not less than 1")
# Output: 2 is not less than 1

For Loop

The for loop allows you to execute a block of code repeatedly for a specific number of times. Here’s an example:

for i in range(3):
  print(i)
# Output:
# 0
# 1
# 2

While Loop

The while loop allows you to execute a block of code repeatedly as long as a certain condition is met. Here’s an example:

i = 0
while i < 3:
  print(i)
  i += 1
# Output:
# 0
# 1
# 2

Survival game made with Godot 4

Functions

Functions allow you to group a set of related code together and reuse it whenever you need it. Functions make your code more organized and readable. Here’s how to define and use functions in GDScript.

Defining Functions

You can define a function using the “func” keyword, followed by the function name, a list of parameters in parenthesis, and a block of code inside curly braces. Here’s an example:

func greet(name):
  print("Hello, " + name)

greet("John")
# Output: Hello, John

Return Statement

The return statement allows you to return a value from a function. Here’s an example:

func square(x):
  return x * x

result = square(3)
print(result)
# Output: 9

Optional Parameters

You can specify default values for parameters in case they are not provided when the function is called. Here’s an example:

func greet(name, greeting="Hello"):
  print(greeting + ", " + name)

greet("John")
# Output: Hello, John
greet("Jane", "Hi")
# Output: Hi, Jane

Variable Number of Parameters

You can accept a variable number of parameters by using the “*args” syntax. Here’s an example:

func sum(*numbers):
  result = 0
  for number in numbers:
    result += number
  return result

print(sum(1, 2, 3, 4))
# Output: 10

Skiing mini-game made with Godot 4

Classes and Objects

Classes and objects are fundamental concepts in object-oriented programming (OOP). They allow you to create complex data structures and provide a way to encapsulate data and behavior. Here’s how to use classes and objects in GDScript.

Defining Classes

You can define a class using the “class” keyword, followed by the class name and a block of code inside curly braces. Here’s an example:

class Person:
  var name

  func greet():
    print("Hello, my name is " + name)

person = Person.new()
person.name = "John"
person.greet()
# Output: Hello, my name is John

Constructor

The constructor is a special method that is automatically called when an object is created from a class. You can use the constructor to initialize the object’s properties. Here’s an example:

class Person:
  var name

  func _init(name):
    self.name = name

  func greet():
    print("Hello, my name is " + name)

person = Person.new("John")
person.greet()
# Output: Hello, my name is John

Inheritance

Inheritance allows you to create a new class that is a derived version of an existing class. The derived class inherits all the properties and methods of the base class. Here’s an example:

class Employee(Person):
  var company

  func work():
    print(name + " is working at " + company)

employee = Employee.new("Jane")
employee.name = "Jane"
employee.company = "Acme Inc."
employee.greet()
employee.work()
# Output:
# Hello, my name is Jane
# Jane is working at Acme Inc.

Polymorphism

Polymorphism allows you to use an object of a derived class anywhere an object of the base class can be used, because the derived class is considered a subclass of the base class. Here’s an example:

func introduce(person):
  person.greet()

introduce(person)
introduce(employee)
# Output:
# Hello, my name is John
# Hello, my name is Jane

Turn-based RPG made with Godot 4

Error Handling

Error handling is an important aspect of programming. It allows you to gracefully handle unexpected situations and prevent your program from crashing. Here’s how to handle errors in GDScript.

Try-Except Blocks

The try-except block allows you to wrap a block of code that might raise an exception, and handle the exception if it does. Here’s an example:

try:
  # code that might raise an exception
  print(1 / 0)
except DivisionByZero:
  # code to handle the exception
  print("Cannot divide by zero.")
# Output: Cannot divide by zero.

Raising Exceptions

You can raise an exception explicitly using the “raise” keyword, followed by an exception object. This allows you to signal that something unexpected has happened and stop the execution of the current function. Here’s an example:

func divide(a, b):
  if b == 0:
    raise ValueError("Cannot divide by zero.")
  return a / b

try:
  result = divide(10, 0)
  print(result)
except ValueError as error:
  print(error)
# Output: Cannot divide by zero.

Custom Exceptions

You can create your own custom exception classes to signal specific error conditions. Here’s an example:

class DivisionByZeroError(Exception):
  pass

func divide(a, b):
  if b == 0:
    raise DivisionByZeroError("Cannot divide by zero.")
  return a / b

try:
  result = divide(10, 0)
  print(result)
except DivisionByZeroError as error:
  print(error)
# Output: Cannot divide by zero.

Physics sandbox game made with Godot 4

File Input and Output

In this section, you’ll learn how to read from and write to files in GDScript. This is useful for storing data that you want to persist across multiple runs of your program.

Writing to Files

You can write to files using the “File” class in GDScript. Here’s an example that writes a message to a file:

var file = File.new()
file.open("message.txt", File.WRITE)
file.store_string("Hello, world!")
file.close()

In this example, we create a new “File” object, open a file named “message.txt” for writing, store the string “Hello, world!” in the file, and then close the file. If the file doesn’t exist, it will be created. If it does exist, its contents will be overwritten.

Reading from Files

You can read from files using the “File” class in GDScript. Here’s an example that reads a message from a file:

var file = File.new()
file.open("message.txt", File.READ)
var message = file.get_as_text()
file.close()
print(message)
# Output: Hello, world!

In this example, we create a new “File” object, open a file named “message.txt” for reading, retrieve the contents of the file as a string, and then close the file. We then print the contents of the file to the console.

Error Handling

When working with files, it’s important to handle errors that might occur, such as trying to open a file that doesn’t exist or trying to read from a file that hasn’t been opened for reading. Here’s an example that demonstrates error handling:

var file = File.new()
try:
  file.open("nonexistent.txt", File.READ)
except Error:
  print("Cannot open file.")
finally:
  file.close()
# Output: Cannot open file.

In this example, we create a new “File” object and attempt to open a file named “nonexistent.txt” for reading. If the file doesn’t exist, an “Error” exception will be raised and caught by the “except” block. We print an error message and then close the file in the “finally” block, which will be executed regardless of whether an exception was raised or not.

Conclusion

Congratulations, you’ve now learned the basics of GDScript! You can use this knowledge to create your own games and applications in Godot Engine.

However, there is more to learn than just GDScript. Godot offers a ton of fantastic features and tools – from simple tilemap painters to performant rendering options. Plus, these coding principles – while important – aren’t of any use unless you learn how to apply them practically to game projects.

To end this article, we’ve included a bunch of helpful resources below to help you get started on the next steps in your Godot journey. We hope this helps, and we’re looking forward to seeing what you do with Godot 4!

Primary Resources

Premium Godot Tutorials

Free Godot Tutorials

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
The Best Godot 4 Tutorials – Complete Game Dev Guide https://gamedevacademy.org/godot-4-0-tutorial/ Wed, 05 Apr 2023 05:29:37 +0000 https://gamedevacademy.org/?p=12194 Read more]]> Godot 4 is the newest major update for the Godot game engine. In January 2018, Godot 3.0 was released which introduced many new features such as a new rendering engine and improved asset pipelines. With the official release of Godot 4 in 2023, similar major advancements have come about that are sure to improve game development for users!

In this article, we’ll discuss some of the newest features for Godot 4 – and then show you where you can start learning!

Let’s dive in!

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Vulkan Rendering Engine

One of the major features for Godot 4 is the Vulkan rendering engine. It was introduced to the master branch of the engine back in February 2020, although OpenGL ES 3.0 is still supported. Godot 4 features full implementation of the Vulkan engine. So why make the change? Godot 3 is using OpenGL – which is supported on many platforms. But, as tech is moving forward, compatibility becomes much less of an issue using the Vulkain engine. Vulkan is also much more “lower-level” than OpenGL, allowing it to perform better and faster.

Core Engine Improvements

Godot 4 also features some major updates to the core of the engine. With an update like this, it’s given the developers an opportunity to make these much-needed changes. Here’s a few things that were changed:

  • Support for multiple windows
  • General cleanup of the API
  • Renaming of nodes and servers

Godot multiple windows.

New Lightmapper

Godot’s new lightmapper for 4 is so much of an improvement, that the devs are going to back-port it to Godot 3 as well. Lightmapping is pre-calculating the light for a game scene. This provides the benefit of having realistic lighting at a low computational cost. Here’s how the new lightmapper improves upon the older one while also making the experience easier for you as a developer.

  • GPU based – allowing for faster bake times
  • Easy to use – minimal number of parameters
  • Lightprobes
  • Automatic UV unwrapping

Other Improvement

While the three mentioned above are our favorite improvements, there have been a lot of other features and improvements added to the platform. These include:

  • Improved 2D tools and rendering
  • Shader and visual effects enhancements
  • Tweaks to both GDScript and C# for Godot
  • Overhauled physics
  • Stabilized networking for multiplayer games
  • Better animation tools and performance

Godot’s video below will help summarize everything with the release for your convenience as well (if you want to hear it from the horse’s own mouth, so to speak.

Summary of Godot 4’s Release

To sum it all up, the aim of Godot 4 is not necessarily to introduce a large number of new features, but to improve upon the rendering and engine performance in order to bring it up to the same level as other game engines out there.

However, the importance of a performant engine cannot be overstated – and puts Godot well in the arena to compete with engines such as Unity and Unreal Engine. Regardless, we hope this has excited you for this new release. Now is a fantastic time to learn a new tool if you’re in the market for one, or to re-familiarize yourself with Godot if you thought you knew everything about the engine already!

Without further ado, below we’ve put out our favorite tutorials for Godot 4 (along with some extra resources to speed up your learning process! Good luck, and we can’t wait to see your future Godot game projects!

Best Tutorials and Resources for Godot 4

Important Links

Demos & Key News

Premium Godot Tutorials

General Tutorials

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
What is Godot? The Free Engine for Making 2D & 3D Games https://gamedevacademy.org/what-is-godot/ Wed, 11 Jan 2023 01:00:10 +0000 https://gamedevacademy.org/?p=13232 Read more]]> While there are many game engines available, one you may have heard about through the grapevine is Godot.

Godot has recently seen a rise in the game development scene and is quickly becoming a favorite of many game developers! However, just as many developers have never heard of Godot, or even know why they might want to use Godot over other popular engines like Unity or Unreal. After all, game engine choice is crucial as a first step when developing your games.

In this post, we’re going to walk you through in not only understanding what the Godot game engine is, but also how it can benefit you as a game developer!

Let’s dive in and discover this amazing, free engine.

What is Godot?

First released in 2014 by Juan Linietsky and Ariel Manzur, Godot is a cross platform game engine oriented towards both 2D and 3D game development. The game engine focuses on providing a well-rounded set of tools for development – including a built-in code editor, a graphics rendering engine, audio playback tools, animation tools, and more. Over the years, the engine has grown immensely to include even more core contributors – and also accepts help from the Godot community as well to further develop the engine.

The Godot logo

Key Features

Let’s jump into some of the key features offered by the Godot game engine.

3D Graphics Support

As mentioned, Godot comes with many features needed for 3D graphics. This includes lighting systems, physics systems, material support (reflection, refraction, etc.), and even tools for post-processing effects. Further, the engine also supports more advanced graphics features such as shaders and particles, giving developers a full set of tools to customize their games.

Fully-Dedicated 2D Engine

Unlike other engines where 2D is achieved simply by flattening a single axis, Godot offers a true 2D engine. This means the engine can both handle 2D backend calculations efficiently, but also appropriately deal with pixel-based units. Further, the 2D game development suite comes with a number of dedicated tools such as tilemap editors, 2D physics support, and 2D lighting systems.

Screenshot of a 2D top down RPG made with Godot

Project Optimization with Nodes and Scenes

Godot is built heavily around the principle of object-oriented design. One of the primary ways it achieves this is with its node and scene architecture. Godot defines every object as a “scene”, and each scene can contain multiple nodes. Godot offers hundreds of nodes that provide base functionality to the game – whether it be collision detection, physics bodies, animations, sounds, etc. Basically, any baseline mechanic you might need to form more complex mechanics can be found as a node.

Due to this, Godot has made a unique system where it is extremely easy to add functions to objects at a very primitive level to create complex objects (i.e. “scenes”). This feature also has the benefit of letting beginners have tight control over inheritance between scenes as well as making instances much easier to handle, particularly compared to other engines.

Multiple Platform Support

Godot allows for deployment to several different platforms, including but not limited to Windows, macOS, Linux, iOS, and Android – all major contenders in the gaming market. Additionally, Godot also allows export for HTML5 for developers who wish to put their games on the web. While Godot does not offer support for consoles at this time due to several complicated factors, such as the console market being fairly unopen, many third-party companies do exist to help support developers who want to port their games to console devices.

Beyond this, Godot also has a robust plugin structure that allows developers to create virtual reality games and limited augmented reality applications as well.

The Godot Engine with a 2D character having the collision box added

Multiple Language Support

Out of the box, Godot allows developers to code their games in several different languages.

At the top of the list is GDScript, which is a scripting language developed specifically for working with Godot. As it was designed to integrate heavily with the Godot Engine itself, many developers have found it the most optimal for working with the engine. As it is similar in many respects to Python as well, developers also find its cleanliness and human readability a plus when developing with the engine.

For those who prefer not to code from scratch, Godot also comes with a visual scripting tool. This tool was designed to work extremely well with its node architecture, meaning non-programmers and beginners can easily use the drag-and-drop code blocks to construct their games.

However, for those more skilled, Godot also supports C++ and C# without much hassle as well – offering developers plenty of options. In addition to these two, Godot’s GDNative API also supports limited language binding, and some developers have found the ability to use languages such as Ruby or R with the engine.

Screenshot of Godot's build-in code editor creating a player

Animation System

Godot offers a robust set of tools for animation. Particularly for 2D, the engine comes with tools to allow developers to rig their 2D graphics and animate their graphics with full IK bone support. However, the engine also supports imported 3D animations as well as 2D sprite sheets. Regardless of the source, Godot also comes with various animator tools to help developers trigger and transition animations when needed.

Open Source

Godot is an open-source engine, meaning the source code for the engine code is publicly available (in this case, through a permissive MIT license). As such, developers with Godot are free to not only distribute the engine as they see fit, but also modify the engine in various ways without constraints.

This also means the engine is community-driven, and developers are free to contribute improvements to the engine code and offer experiences and tools that extend the engine in unique, robust ways. Plus, this means the engine is completely free in itself to use.

Godot Engine showing a 3D animation being made for a sword

What Can Be Made with Godot?

If you can dream it, Godot can probably help you make it. This includes FPS games, RPGs, strategy games, simulation games, turn-based deck builder games, and beyond. However, the best way to see what Godot is capable of is to check out some of their own developer showcases below of current and upcoming games – all made by developers just like you!

Why Choose Godot?

Now that we’ve talked about what Godot is and explored what it can do, let’s jump into the main thing many developers want to know: why should you choose Godot to develop games?

  1. 1. It’s free. As the engine is open-source, it costs you nothing to obtain or use the engine. Unlike Unity or Unreal Engine where a certain amount of revenue will cost you an expensive license, revenue made with Godot-created games are yours to keep with no strings attached!
  2. You can edit the engine as you need to. Again, the engine is open-source. So, if the engine doesn’t quite do what you need it to do for your game project, you can edit the engine directly until you can achieve the effect you want. This gives you the freedom you need to develop whatever systems and mechanics are needed without constraints!
  3. There are few limitations. Outside of performance and console games, Godot has few limitations. You can make games for mobile or even Linux. You can make action RPGs, farming simulation games, RTS games, or even point-and-click games. You can even make animations to just show off your animation skills. Godot doesn’t limit you with the tools they provide, so you can explore your creativity to its limits.
  4. The 2D Engine is generally considered better than other popular 3D engines. Mentioned above, Godot uses a dedicated 2D engine instead of simply pretending a third axis doesn’t exist. This makes it far more efficient at handling 2D graphics, 2D physics calculations, 2D lighting, and so forth compared to other engines like Unity and Unreal. So, if 2D is your aim, Godot definitely outranks a lot of the competition.Screenshot of a Mars city building type game made with Godot
  5. It’s lightweight. Many engines available are pretty hefty on computer systems, especially when they’re more graphics intense. Godot, however, is extremely lightweight, being less than 100MB. The resources it uses are also limited compared to other engines, meaning it is a fantastic engine choice if you have a low-powered system like a laptop as your only computing device.
  6. The engine is community-driven. Partly due to its open-source nature, Godot has attracted a dedicated following. Not only is there a steady stream of developers contributing to the engine’s development in the Godot community, but also tons of users who are ready and willing to answer questions and provide support as you build your game. There are also plenty of tutorials available as well to help users get started with building their own games.
  7. It’s beginner-friendly. Godot offers several tools to make game development very easy for beginners – whether that’s thanks to their visual scripting tools, GDScript’s readability, it’s easy to understand nodes to add functions, or so forth. Whether you’ve created a game before or not, Godot is easy to jump into. Even experienced developers often use Godot to prototype game mechanics simply due to how easy the engine is to use!
  8. Godot has strong version control support. Whether you’re using something popular like Git or other version control systems, Godot was made to be extremely compatible with a simple file setup. This means you can backup your various versions and not have to worry if you break something during the development process!

2D platformer example made with the Godot engine

How to Learn Godot

Interested in Godot after all is said and done? Below, we’ve compiled a list of resources that will allow you to explore the engine further and learn how to use it to create your own game projects!

Screenshot of a simple Action RPG made with the Godot Engine

Conclusion

We’ve only just grazed the surface on what Godot is here. However, hopefully you should have a much better understanding not only of what benefits the engine offers, but also how you might learn to utilize those benefits for your own game projects. Whether you’re looking to build some exciting 3D action RPGs or some simple 2D platformers, Godot is able to easily cater to your project needs. This is not to mention it is a great choice for beginners as well given how the engine has organized functionality into nodes for easy access. There is a lot to be had with this amazing tool, so get out there, make some games, and show just what you can do as a game developer!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
How to Create a Game with Godot 4 – Beginner’s Tutorial https://gamedevacademy.org/godot-4-game-tutorial/ Mon, 09 Jan 2023 03:02:55 +0000 https://godottutorials.pro/?p=3819 Read more]]> Want to make games, but are tired of everything being about Unity and Unreal Engine?

Godot is a great game engine for both 2D and 3D games – making it a multi-purpose engine suitable for many kinds of projects. It’s also open source and has a strong community backing the project, so there are constant updates and new features being released. With the release of Godot 4, it’s also better than ever to explore game development with this fantastic tool.

In this tutorial, we’re going to be learning how to create a very simple coin collection game in Godot 4. We’ll discover not only some of the core tools offered by Godot, but how to use GDScript to render our various mechanics.

Without wasting any more time, let’s dive in!

Project Files

You can download the complete project we’ll be making in this tutorial here.

While we’ll include it later below, you may also wish to download the character sprite and coin sprite that we’ll be using as well.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Installing Godot

Right now, Godot 4 is in beta, so let’s go to the Beta Download Page and click Standard Build.

Downloads page showing the Standard build highlighted

Then, we want to click on the download that matches our operating system to begin the download.

Page showing the Godot 4 files available for download

Once that the download is complete, you should have a ZIP file which you can extract the contents of. The application file is the game engine, so we can double click on that to open it up.

User downloads folder with the Godot 4 beta application highlighted

Creating a Project

You should now have the Project Manager window open. This is where all of your Godot projects will be listed. For now, we have none, so let’s create one. Click on the New Project button.

Project Manager window in the Godot Engine with New Project circled

This will open up another window where we need to setup a few things.

  1. Choose a Project Name.
  2. Choose a Project Path. This will be where the project files are located on your computer.
  3. Then, click Create & Edit.

Create New Project window for Godot

Editor Overview

After you create the project, the Godot editor should open up. This is the window where we’ll be spending most of our time in creating our games. This is where we will manage our assets, build our levels and code our gameplay behaviors. At first, this may seem daunting. There are a number of different panels, buttons, and labels. But hopefully, as time goes on, it will all become second nature to you.

Blank Godot project as seen in the Godot editor

Let’s start by looking at what each of these panels do. First, in the center, we have our scene view. This is a window into our game and where we’ll be clicking on objects, dragging them in, and building our levels. At the moment, the engine is set to 3D, so that’s why we have a 3D view.

Godot Editor with the main Editor viewport circled

On the bottom left, we have our File System. This panel contains all of our assets (textures, models, sprites, sound effects, scripts, etc). It’s very similar to the file explorer on your computer.

Godot Editor with the File System panel circled

At the top left, we have the Scene panel. This here is a list of all the nodes currently in our scene. The way Godot works is with a node system. We’ll get more into that later, but it’s important to know that everything in your game (the player, camera, objects, lights, etc) are all nodes. And a scene is a collection of nodes.

Godot Editor with the Scene panel circled

On the right-hand side of our editor, is the Inspector. Whenever we select a node, this panel will populate to show us all of that node’s properties. Its position, rotation, scale and any other things that we might want to modify. If it’s a light node, then the inspector will allow us to change the color, brightness, range, angle, etc.

Godot Editor with the Inspector panel circled

At the top right corner of the screen, we have our play tools. These allow us to test out our game while we’re developing it. We can play, pause, stop, run the current scene, run a specific scene, or use the movie maker.

Godot Editor with a closeup of the play options for Godot

At the top center of the screen, we have a few buttons. These allow us to change what we see down in the large, center-scene viewport. Right now, it’s set to 3D, so that’s why we see our 3D scene. But we can easily switch over to 2D if that’s the type of game we want to create. When we start to code, we’ll be hopping over to the Script tab, as that’s where the text editor is contained.

Godot Editor showing the 2D, 3D, Script, and AssetLib options

For this tutorial though, we’ll be creating a 2D game. So let’s click on the 2D button to switch the window over to 2D mode.

Godot Editor with the 2D button clicked to make a 2D Godot project

Nodes

Now that we’re ready to begin, let’s go over to the Scene panel and create our first root node. Select the 2D Scene.

Godot Scene panel with 2D Scene selected as the Root Node

This is going to create our root node, which is now visible in the list. The way Godot works is through nodes. Everything in your game is nodes. 3D models, tiles, blocks, the player, enemies, UI – everything that can have a position in space or be instanced is going to be a node. Now with these nodes, they can be nested inside of each other. For example, a player node will also have a child node that acts as a collider. Another child node renders its sprite to the screen and another child node for the camera.

If you wish to learn more about Nodes and Scenes, check out the Godot documentation.

Now before we continue, let’s save our scene. A scene is basically a collection of nodes that can be loaded into our game. Press CTRL + S or go to Scene > Save Scene As to save. Let’s call it Level1.tscn, then click Save.

Creating the Player

Let’s get started on creating our player. We, first of all, need to figure out what node we want our player to be, because each node has a specific type. Each node type serves a different purpose, and for our player, we’ll be using a CharacterBody2D node. So to get started, go to the top right corner of the Scene panel, and click on the + icon.

In the Create New Node window, search for CharacterBody2D, select it, then click Create.

Godot CharacterBody2D node circled from the Create New Node window

This will create the node. Now we can double-click on it to rename the node. Rename it to Player.

Player node as seen in the Scene panel of Godot

Now that we have our root player node, we need to give them a visual.

Download this ZIP and extract the PNG inside.

With the image downloaded and extracted, drag it into the FileSystem panel to import.

Character sprite as seen in the Godot FileSystem

Now on our player node, right click it and select Add Child Node.

Add Child Node option highlight for the Player Node in Godot

Search for Sprite2D, select it and then click Create.

Create New Node window in Godot with Sprite2D selected

With the new child node selected, look over at the Inspector and you should see that the panel has a bunch of information. There is a texture property that we need to enter. From the FileSystem, click and drag the character sprite over into the field to assign it.

Sprite assigned to Sprite2D node in the Godot Inspector

Now we can zoom into the player in the scene view, but you’ll notice that it’s blurry.

Blurry sprite as seen in the Godot editor space

To fix this, select the sprite node, go to the inspector, and under the Texture drop-down, set Filter to Nearest.

Godot Inspector with Nearest set for the Texture filter of the Sprite2D node

Our player also needs a collider, so add a new child node of the type CollisionShape2D.

Player node with CollisionShape2D node added in Godot's Scene panel

In the inspector, you can set the Shape to be a RectangleShape2D. Then in the scene view, click and drag on the orange dots to fit it to our sprite.

2D collision box as seen in both the Godot Editor and in the Inspector

And there we go! We now have our player created. Let’s move on to coding, where we’ll get our player moving around.

Moving the Player

To move the player, we need to create a script. This is basically a text file that contains code. The engine can read that and apply whatever gameplay behaviors we define.

With the Player node selected, go down to the bottom of the inspector. Click on the down arrow next to Script and select New Script.

Node creation options with Script options shown

Call it Player.gd then click Create.

Attach Node Script window in Godot with Player script being created

This will then switch us from 3D mode to Script mode and we’ll see some default code here:

Godot script showing default code for movement

Delete everything except for the first line.

Clean Godot script with only "extends CharacterBody2D" left

Now let’s add in some code:

func _physics_process(delta):
  
    velocity = Vector2()
  
    if Input.is_key_pressed(KEY_LEFT):
        velocity.x -= 1
    if Input.is_key_pressed(KEY_RIGHT):
        velocity.x += 1
    if Input.is_key_pressed(KEY_UP):
        velocity.y -= 1
    if Input.is_key_pressed(KEY_DOWN):
        velocity.y += 1
    
    velocity *= 50	
    
    move_and_slide()

What we’re doing here is detecting inputs from the arrow keys, then changing the value of our velocity based on that. At the end, we’re multiplying it all by 50, so that we move at 50 pixels per second. And finally, move_and_slide will apply those changes to our CharacterBody2D.

If you now go to the top right corner of the screen and click on the Play button, you can test it out.

Godot project playing in editor

One thing you will notice, is that after you press play, a window will open. But our player is so small! And it’s in the top left corner of the screen. To fix this, we can go to our player node and add a new child node of type Camera2D.

Godot Scene panel with Camera2D node added to the Player node

Then in the inspector, make sure to enable Current. And for the Zoom, set that to 3, 3. This will make it so the camera is closer to the player and we can get a much better view of them.

Camera2D node in Godot's Inspector showing Zoom options

Now when you press play, it should look like this:

Godot project playing with zoom on character from Camera2D node

Collectibles

When we play our game, there’s one problem. There’s nothing to do! So let’s add in some coins that the player can collect.

To begin, download the coin sprite and import it into your project.

To begin, download the coin sprite and import it into your project.

Godot FileSystem showing a new tile sprite for coins available

Next, in the Scene panel, click on the + and create a new node of type Area2D. Make sure to rename it to Coin. Then as a child of Coin, add a Sprite2D node.

Coin node with Sprite2D node added in the Godot Scene panel

In the Inspector:

  • Set the Texture to be the coin sprite.
  • Set the Position to 0, 0.
  • Set the Filter to Nearest.

Select the Coin node, then at the top of the scene window, select the Move Tool. This will allow us to click and drag on the coin to move it around our scene.

Godot scene with the coin added and moved from behind the player

As a child of the Coin, create a CollisionShape2D node. Then in the Inspector, set the Shape to CircleShape2D. We can then click and drag on the orange circle to resize the collider.

Coin with the Collision2D node added to the coin node object in Godot

Finally, let’s create a script for the coin.

  1. Select the Coin node.
  2. In the inspector, create a new script called Coin.

Here’s what our Script panel should look like now.

Script Panel in Godot with the Coin script added

With the Coin selected, go over to the inspector and swap over to the Node tab. Here, we want to double-click on body_Entered(body: Node2D).

Node panel in Godot with body_entered circled under the Area2D options

In this window, select the Coin and click Connect. What we’re doing here is basically setting it up so that the coin script gets informed when a body hits the coin collider.

Connect Signal to a Method window in Godot with Coin circled

This new bit of code should then be added to the script automatically.

Godot coin script with new functionality automatically added

Delete the “pass” line of code and add these three new lines:

func _on_body_entered(body):
    body.scale.x += 0.2
    body.scale.y += 0.2
    queue_free()

What we’re doing here, is increasing the size of the colliding object (player) when they hit the coin. Then with queue_free(), we are destroying the coin so the player can only collect it once.

Back in our 2D panel, let’s make some more Coins. The best practice is to turn it into a scene. Much like how our level is saved as Level1.tscn, we are going to make our coin a scene. This means we can have many different instances of it in our scene which all inherit from the same blueprint. So to do this, click and drag the coin node into the FileSystem. Call it coin and click save.

Coin object node dragged to FileSystem in Godot

Now we can duplicate the coin (Ctrl + D) and move them around like so.

Godot scene with many instances of Coin added

Press play and we can test it out!

Play test of character and coins in Godot project

Conclusion

And there we go! We’ve made a small, introductory game with the Godot game engine. While this game is very simple, it does serve to not only show you what Godot 4 is all about, but some of the core tools you’ll be using in any Godot game project.

From here, you can expand upon our project, or create an entirely new game with the knowledge that you’ve learned. Perhaps you’ll want to turn this into a platformer with tons of jumping mechanics. Or maybe you want to make a bullet hell or even a strategy game. There is a ton left to explore, but hopefully these foundations will help you in taking that next step.

If you’re interested in learning more about the specifics with Godot, then you can read their documentation here. Thanks for following along, and good luck with your future Godot 4 games!

]]>