Skip to content

Instantly share code, notes, and snippets.

@gnat
Last active October 5, 2023 21:59
Show Gist options
  • Save gnat/d212b879395de6e1723972f80a107e66 to your computer and use it in GitHub Desktop.
Save gnat/d212b879395de6e1723972f80a107e66 to your computer and use it in GitHub Desktop.
Godot 4 Quickstart

Godot 4 - Fast quickstart!

Legend

  • ♻️ Workflow
  • πŸ› οΈ Tool
  • πŸ“¦ Asset or Library
  • ⭐ Guides
  • 🎨 Pattern
  • πŸ”₯ Hot Tip

Read me first!

Feature Demos

Shaders

Collaboration / Team Workflow

  • ♻️ Overview
    • πŸ”₯ Avoid massive scenes. Split into many scenes!
      • 🎨 Use Right Click ➑️ Save Branch as Scene. Branch will become an instance of the new scene!
        • Each scene is a seperate file: will eliminate conflicts.
        • "I am working on X scene today"
      • 🎨 Use the /actors/ and /skins/ pattern to break up scenes even more.
    • 🎨 Use Merge from Scene for complex visual merges. Similar to Unity merge
    • πŸ“¦ Improved git

Asset Pipeline

Library

Code

Code - App

  • 🌌 OS App code. Loaded first. Can execute() kill() alert()
    • For tool development!
    • 🎨 Open in web browser OS.shell_open("https://godotengine.org")
  • 🌎 SceneTree Manages all Scenes / Nodes. Default main loop.
    • 🎨 get_tree() get the SceneTree
    • ⬇️ See below! ⬇️

Code - Scenes / Nodes

  • 🌎 SceneTree Manages all Scenes / Nodes. Default main loop.
    • 🎨 get_tree() get the SceneTree
    • 🎨 Change scene get_tree().change_scene_to_file("res://path/to/scene.tscn")
  • πŸ” Find
    • 🎨 $ is shorthand for get_node()
      • $AnimatedSprite2D.play() is the same as get_node("AnimatedSprite2D").play()
      • πŸ”₯ Go deep: $screen_gameplay/hud/score
        • ♻️ Click and drag from outline to code to insert path!
        • 🎨 Deep paths getting long? Alias ($"%PauseButton") using unique in-scene ID 1:40+
      • πŸ”₯ Prevent errors with if $thing: $thing.do_it()
      • Loop through all nodes in group for node in get_tree().get_nodes_in_group('enemy'): Video
    • 🎨 Alternative: get_node("/root/main")
  • 🟒 Create
    • 🎨 Instantiate (... in main.gd or screen_gameplay.gd.. whatever)
      • @export var enemy_scene: PackedScene = load("res://entity/enemy_purple.tscn")
      • var enemy = enemy_scene.instantiate()
      • add_child(enemy)
  • ❌ Remove
    • 🎨 Delete node queue_free()
    • 🎨 Clear child nodes for child in get_parent().get_children().kill(child)

Code - Physics

  • CharacterBody3D High level player-controlled entity.
    • move_and_slide() Engine will smooth out collisions.
    • is_on_floor()
  • RigidBody3D High level physics-controlled entity.

Code - Physics Collisions

  • πŸ”₯ Layers & Masks save you from writing physics "collision check" code. (Default: all 1 layer)
    • Layers: Which layer(s) a node / scene is on.
    • Masks: Which layer(s) a node / scene will detect.
  • πŸ”₯ Add signals to a CollisionShape3D: Make it a child of Area3D (Respond to body_entered and area_entered!)
    • Ex: area_enemy ➑️ collision_shape_3d
    • Set area_enemy ➑️ Monitorable to OFF if you want to only emit signals, not auto-interact with other collision shapes.
    • body_entered πŸ‘ CharacterBody3D or RigidBody3D .... area_entered πŸ‘ Area3D

Code - 3D

  • Vector3 can look_at() and has useful constants Vector3.ZERO, Vector3.UP
  • Nodes have both position and global_position
  • Nodes have both _physics_process(delta): and _process(delta):
    • _physics_process(delta): runs at 60 fps always.
    • _process(delta): runs as often as possible (framerate).
    • use the delta to move things at a consistent rate in either function.
  • Dot Product (compare the angle between two vectors)
    • Useful for detecting if 3D character is on top/front/bottom of enemy or platform.
      • if Vector3.UP.dot(collision.get_normal()) > 0.1: enemy.die()

Code - GUI / 2D

  • πŸ”₯ Will always be overlayed on top of the 3D. Go to "2D view" to preview.
  • Build a "screen": Node3D ➑️ Control ➑️ Label

Code - Signals + Lambdas

image

Code - Performance

  • Threaded resource loading - can load up to ten times faster!
    • ResourceLoader
      • ResourceLoader.load_threaded_request("res://scene.tscn","",true)
      • var thing = ResourceLoader.load_threaded_get("res://scene.tscn")

Code - Future

Marketing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment