Adding a Hitstop Singleton/Autoload to your Godot project

Here's my basic code for a Hitstop implementation, I usually put it up as a singleton/autoload node in my project so it can be called from anywhere globally.

extends Node2D


var original_timescale = 1.0
# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


func hit_stop_global_basic(intensity):
	# t for time, total duration the hitstop neeeds to activate for
	
	var tween  = create_tween()
	var default_duration = 0.1 # 100ms?
	#tween.set_parallel(true)
	
	# We define our enum intensities here
	if(intensity=="hard"):
		default_duration=0.25
	
	Engine.time_scale = 0.1
	#tween.tween_property(Engine,"time_scale",0.2,1.0)
	tween.tween_property(Engine,"time_scale",1.0,default_duration)


You must have noticed, that I use a tween instead of timers as it can be done with code instead of creating additional nodes, works great, and is neat, and concise. This code introduces so much power to the game, takes just about 5 minutes to improve the game feel of your game by a lot


This is how you finally end up calling it in your game


@onready var HitStop = get_node("/root/Hitstop")

func _ready():
  HitStop.hit_stop_global_basic("hard")