Skip to content

Instantly share code, notes, and snippets.

View WolfgangSenff's full-sized avatar

Kyle Szklenski WolfgangSenff

View GitHub Profile
@WolfgangSenff
WolfgangSenff / gist:3c8813a799965d3087f4223cf3e44aba
Created September 29, 2022 12:39
Godot RPG Movement Script Template
# meta-description: Classic movement for RPG or top-down games that do not apply gravity
# meta-name: RPG movement
# meta-default: true
# meta-space-indent: 4
extends _BASE_
const SPEED = 450.0
const FRICTION = 1000.0
@WolfgangSenff
WolfgangSenff / .gd
Created December 9, 2022 14:10
A horizontal shake method to help add hit stops to your games!
extends Node
# Make this a global singleton if you want
func shake_horizontal(thing, strength: float) -> void:
var orig_pos = thing.position
var current_amount = 6
var shake_count = int(abs(current_amount))
for i in shake_count: # Tweak these values
var tween = create_tween().tween_property(thing, "position", Vector2.RIGHT * pow(-1, i) * strength * current_amount, 0.01)
await tween.finished
@WolfgangSenff
WolfgangSenff / gist:827b8daf74e4f63312a7d0c9d053d904
Created December 18, 2022 10:46
Calling functions on other scripts in Godot
# In your Enemy.gd script
...
const KILL_EFFECT_SCENE = preload(...)
func take_damage(amount: float) -> void:
enemy_stats.hitpoints -= amount
if enemy_stats.hitpoints <= 0:
kill()
@WolfgangSenff
WolfgangSenff / ShakeCamera2D.gd
Last active January 26, 2023 17:13
Camera shake from KidsCanCode
extends Camera2D
# Courtesy of KidsCanCode: http://kidscancode.org/godot_recipes/3.x/2d/screen_shake/ (this may change in the near future, so it may require a search)
# If you intend to use this, don't forget to turn on camera rotation! And keep in mind that smaller numbers are often the most useful - huge numbers make this thing *really* shake
# 3.5.x
export var decay = 0.8 # How quickly the shaking stops [0, 1].
export var max_offset = Vector2(100, 75) # Maximum hor/ver shake in pixels.
export var max_roll = 0.1 # Maximum rotation in radians (use sparingly).
export (NodePath) var target # Assign the node this camera will follow.
@WolfgangSenff
WolfgangSenff / gist:0a9c1d800db42a9a9441b2d0288ed0fd
Last active February 15, 2025 13:47
GDScript 1.0 to 2.0 Beginner Friendly Conversion Guide
Beginner-friendly GDScript 1 to GDScript 2 Conversion Guide
First and foremost, this should not be considered a replacement for the official migration guide,
found at https://docs.godotengine.org/en/latest/tutorials/migrating/upgrading_to_godot_4.html!
Instead, this document is intended to be a friendly guide to helping you upgrade your projects from
GDScript 1 to 2. To do this, I'm going to list the most common conversions I've run into while upgrading
a few of my games and tools. This document is written as of the first release candidate version of Godot 4.0.
The first thing to do when converting a project (no need if you're starting from new) is to either have your
project in source control, or make a duplicate of your entire project's folder and rename it. This will
extends Sprite2D
const MoveSpeed = 50
var _initial_y
func _ready():
_initial_y = global_position.y
func _process(delta: float) -> void:
@WolfgangSenff
WolfgangSenff / PDA.gd
Created June 3, 2023 11:58
Pushdown Automata Godot 4.0
extends RefCounted
class_name StateMachine
class PDA:
var stack = []
func push(state):
if stack.size() > 0:
stack[-1].exit(state)
stack.append(state)
@WolfgangSenff
WolfgangSenff / AutoAdvanceState.gd
Created December 5, 2023 15:33
Binding arguments in GDScript
func _ready() -> void:
$AnimationPlayer.animation_finished.connect(_on_animation_finished.bind(func(): $StateMachine.change_to($StateMachine/JumpState)))
# Above will add an extra argument to the function when animation_finished is emitted that's equal to the Callable in this case.
# The callable is used below. Note the change in signature to the function for the signal.
func _on_animation_finished(anim: String, on_complete: Callable) -> void:
on_complete.call() # This ensures that the func() we passed in on line 2 is executed only after an animation is finished.
# You might want this if, for example, you have a longer "start" to an animation, but the part which repeats is
# a separate animation. I use this for when a special attack has a "wind-up", but the wind-up isn't part of
# the repeated animation.
@WolfgangSenff
WolfgangSenff / world.gd
Last active February 2, 2024 14:43
For White...
extends Node2D
const BLOCKS... # Copy/paste all blocks here
var blocks_array = [BLOCKS_TYPE_I, ...] # Add them all into this array
@onready var block_spawner = $BlockSpawner
@onready var safe_zone = $SafeZone
var spawn_countdown := 0.0
@WolfgangSenff
WolfgangSenff / player.gd
Created February 20, 2024 16:03
For Bubs
extends CharacterBody2D
# ... variables
@onready var anim = $AnimationPlayer
@onready var sprite = $Sprite2D # Both assume you have an AnimationPlayer node as a child, and Sprite2D
var current_animation = "idle"
func _physics_process(delta: float) -> void:
current_animation = "idle"