Godot Game Engine Fundamentals Notes

Godot Game Engine Fundamentals

Overview
  • This video introduces the Godot game engine and its fundamental concepts.

  • Key topics covered include setting up the program, working with tile maps, utilizing animation players, implementing lighting and particle effects, applying shaders, designing user interfaces, creating skeleton animations, and implementing pathfinding.

  • The tutorial aims to provide a solid understanding of creating 2D games and serve as a foundation for developing 3D games in Godot.

What is Godot?
  • Godot is a comprehensive game engine, a software application that manages and displays images, plays sounds, and processes user input to create interactive experiences.

  • It handles complex tasks such as physics calculations, path finding algorithms, skeleton animations for character movements, and networking functionalities for multiplayer games.

  • Godot supports both 2D and 3D game development, offering a versatile platform for various types of games.

  • Alternatives include popular engines like Unity and Unreal, each with its own strengths and weaknesses.

  • Godot is free and community-developed, eliminating the need for payments, subscriptions, or proprietary accounts.

Downloading and Setting Up Godot
  • Visit godotengine.com to download the latest version of the Godot game engine.

  • Choose the appropriate version for your specific operating system (Windows, macOS, Linux).

  • After downloading, extract the ZIP file to access the Godot executable and a console window, which is used for debugging purposes but can generally be ignored during regular use.

  • Run the Godot executable to launch the Godot launcher.

Godot Launcher
  • The Godot launcher displays a list of previously created projects, enabling quick access to existing games or applications.

  • It offers options to create a new project from scratch or import an existing project from external sources.

  • When creating a new project:

    • Specify a unique project name and a destination folder to store project files.

    • Choose a rendering engine:

      • Mobile: The default renderer, suitable for both desktop and mobile 2D/3D games, providing a balance between performance and visual quality.

      • Forward Plus: Designed for high-end 3D graphics, offering advanced rendering features and improved visual fidelity.

      • Compatibility: Optimized for older devices or browser-based games, ensuring broader compatibility but with reduced graphical capabilities.

    • This tutorial uses the Mobile renderer, but the choice of renderer does not significantly affect the tutorial's content or functionality.

Fundamental Concepts: Nodes and Scenes
  • Nodes are the fundamental building blocks in Godot, representing individual elements within a scene. Examples include:

    • Images (Sprite2D) for displaying visual content.

    • Sounds (AudioStreamPlayer) for playing audio effects and music.

    • Timers (Timer) for managing time-based events and delays.

    • Paths (Path2D/PathFollow2D) for defining movement paths for game entities.

    • Skeletons (Skeleton2D) for creating and animating skeletal characters.

    • Areas (Area2D) for detecting collisions and interactions between objects.

  • Nodes are combined and arranged to create complex game elements and functionalities.

  • Each node has a set of properties that can be modified in the Inspector panel, such as position, scale, rotation, and other attributes related to its behavior.

  • Scenes are used to organize and display nodes, acting as a container for managing multiple elements within a specific context.

    • Scenes function as both a canvas and a folder, providing a visual representation of the current project structure and hierarchy.

    • Scenes can be nested within other scenes to create logical objects and complex structures, such as placing a scout character within an outdoor level.

Godot UI Recap
  • Center: The primary workspace displaying the currently open scene in either 2D or 3D view.

  • Left: The scene tree, listing all nodes present within the current scene, allowing for easy selection and manipulation.

  • Right: The Inspector panel, which shows the properties and settings of the selected node, enabling customization and fine-tuning.

  • Bottom Left: The file system panel, providing access to project assets, including graphics, audio files, and other resources for importing into the game.

Importing Assets
  • Download the required resources from the video description, including the complete game project and associated assets.

  • Extract the contents of the downloaded ZIP file to access the individual assets and project files.

  • Drag and drop folders containing assets (graphics, audio) into Godot's file system to import them into the project.

Editor Settings
  • Customize the editor's theme to enhance the visual experience during development.

  • Navigate to Editor -> Editor Settings to access customization options.

  • Select a different theme (e.g., Dark theme, Gray Theme) to personalize the editor's appearance.

Creating Basic Scenes and Nodes
  • Objective: Create a Level scene and a Player scene, and then instantiate the Player scene within the Level scene.

  • Steps to create a Level scene:

    • Switch to the 2D workspace in the Godot editor.

    • Create a new 2D scene by selecting the root Node2D.

    • Rename the Node2D to Level for better identification.

    • Save the scene as level.tscn inside a levels folder within a scenes folder to maintain organization.

    • Add a Sprite2D node as a child of the Level node to display visual content.

    • Assign an image (e.g., icon.svg, the Godot logo) as the texture for the Sprite2D node.

Coordinate System
  • The origin point (0, 0) is located in the top-left corner of the screen.

  • The X-axis increases towards the right.

  • The Y-axis increases downwards, which is inverted compared to typical high school coordinate systems.

Parent-Child Relationships
  • Transformations (position, rotation, scale, skew) applied to a parent node automatically affect all its child nodes.

  • Transformations applied directly to a child node are relative to the parent's transformation.

  • Nodes are drawn in the order they appear in the scene tree, with lower nodes rendered on top of higher nodes.

Creating a Player Scene
  • Create a new 2D scene (Node2D).

  • Rename the Node2D to Player.

  • Save the scene as player.tscn in a player folder within the scenes folder.

  • Add a Sprite2D node as a child of the Player node (player image).

  • Add another sprite to the Player, and this is going to be a laser.

  • This new sprite is the "laser image", the source is from projectiles.

Instantiating Scenes Inside Other Scenes
  • Use the "Instantiate Child Scene" icon (chain link) or Ctrl+Shift+A to place a scene inside another scene.

  • Example: Place the Player scene inside the Level scene.

  • Whatever changes you are making to the reference scene will reflect in other scenes.

Creating a Bed Scene (Static Object)
  • Create a new 2D scene (Node2D).

  • Rename the Node2D to Bed.

  • Save the scene as bed.tscn in an objects folder within the scenes folder.

  • Add Sprite2D nodes for the bed and pillows.

  • Add the images as textures.

  • Arrange the sprites for the pillows.

  • Add the bed scene inside of the level scene.

Naming Conventions in Godot
  • PascalCase: Use for node names (e.g., SmallPillow with no space in between, every word starts with a capital letter).

  • snake_case: Use for everything else (e.g., file names: all lowercase letters, spaces replaced by ).

Drawing Order
  • The order of nodes in the scene tree determines the drawing order.

  • Nodes lower in the list are drawn on top of nodes higher in the list.

Running the Game
  • Click the "Run Project" icon (play symbol) in the top right corner.

  • If no main scene is selected, Godot will prompt you to select one.

  • Select the Level scene as the main scene.

Coding in Godot (GDScript)
  • GDScript is the default language and is similar to Python.

  • Key differences from Python:

    • Data Types: Integers, Floats, Booleans, Strings, Dictionaries, Arrays (replaces lists).

    • Variables: Normal variables (var keyword) and constants (const keyword).

    • Functions: Use func keyword instead of def.

    • Type declaration:

      • Variables can be forced to only work with a specific kind of data.

      • Parameters can have a certain data type, in this example Integers and Strings.

      • Can also specify return value, a Booleam in this example.

  • Classes: When you create a script, you always have to add it to a node, which is a class.

  • Inbuilt Functions: Start with an underscore, such as _ready and _process.

  • Targeting Nodes: Using either getnode("nodepath") or $"node_path". Using $ is more commonly used because it is much more concise.

Coding Examples in Godot
  • Ready Function: Called whenever the node is ready.

  • Process Function: Called on every frame of the game.

  • Printing Examples: You can print strings when the ready and process node is called.

  • Transform Properties: Used for position, rotation, and scale.

  • Vectors: For the position, you need to create a Vector2 for the x and y axes.

  • Local Variables: Can only be used inside of the function they are declared in. Can see identified errors early.

Targeting one node from another node
  • Level nodes are used to influenced sprites.

  • Example: Target the position dot x from the level node.

If statements and For Loops
  • If statement: If rotation is more than 180 degrees, change it back to zero.

  • For loops: Use to iterate through arrays. Test, Hello, and Stuff are printed as the contents of the array.

Delta Time
  • Delta time measures how long it took to create the current frame.

  • Important to ensure constant speed of any object in the game regardless of the frame rate.

  • Speed Movement * DeltaTime. Fixes that if frame rate changes, the speed stays consistent.

  • If use delta time, you want to use larger numbers to account for it.

Player Input
  • Two Steps to capture in Godot, an Input Map and Accessing Variables.

  • Input Map

    • Create a new event, enter in events and select what Keys to associate.

    • New actions such as Left, Right, Up, Down, and Primary Action.

  • Access the Input

    • Get Vector2D from the keys

    • Change movement based off the direction the inputs are triggered.

  • Create a variable.

  • Add input is action pressed.

Physics
  • Images don't have physical properties, to do that physics bodies are needed.

  • Area2D checks when another body has entered the area and moves by, the position is moved.

  • StaticBody2D collides with other bodies, though it doesn't move. Obstacles or bats are examples.

  • Rigidbody2D moves via physical forces, like setting a velocity, and the body moves on its own.

  • CharacterBody2D is a moving body that's controlled by code via inbuilt methods, like Move and Slide.

Actions and Signals
  • StaticScene - new Scene - RigidBody2D with children of

    • sprite.png which is just an image

    • collision shape with shape.

  • Update Level Scene, select chain and add the new Scene from Above.

  • Signals, under the Tab - Node, area with other body enters.

    • connect the signal to level or other code.

    • Then print something in the newly, auto-genrated, Function after selected connect.

  • Creating, Using: Timers

    • With variables, and Booleans.

    • Call timer code to set boolean to stop, while loading the timer.

    • Then another signal on complete sets the variable boolean to allow input.

Unique Node Names and Interacting with Nodes via Code
  • Give nodes unique names for easy access.

  • Access properties and methods of nodes.

  • Target nested nodes using $