Skip to content

Instantly share code, notes, and snippets.

# https://www.reddit.com/r/godot/comments/rfzwom/sexystupid_state_machine_in_8_lines/
class_name StateMachine extends Node
signal state_changed
var state:int = 0 setget _set_state
func _init(inital_state:int = 0) -> void:
state = inital_state
pass
# TODO: Make sure it can handle multiple spawn locations
# TODO: Add the ability to trace back along player nav_path to find furthest point to use as distance traveled
# TODO: Add ability to get a point from a percentage along the nav_path
# TODO: Add ability to look forward n distance from where the intersect or player is
# TODO: Add ability to check if player can travel to path without obstacles. if not find another near segment to check from.
# TODO: Add ability to get path ahead from vector3 to distance
extends Node
var director:Node
@Einlander
Einlander / generate_key_maps.gd
Last active February 3, 2021 22:54
Generates some simple keymaps
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _enter_tree():
push_warning("WARNING Generating Key Maps: Be sure to use the Input Map in the release")
@Einlander
Einlander / stair handling.gd
Last active November 28, 2021 19:10
how i handle stairs in my fps
var last_velocity = Vector3.ZERO
var slide_collisions = []
func handle_stairs3(slides:Array, start_position:Vector3, rotation, radius:float,ray:RayCast):
ray.enabled = true
$StepClear.enabled = true
if slides.size()>0:
var selected_slide:KinematicCollision = null
var slide_positions = []
@Einlander
Einlander / path_optimization.gd
Last active December 21, 2020 10:09
Optimizes the navigation meshes get_simple_path() array output
func optimize_path(path:Array,remove_duplicates = true):
#fail early
if path.size() < 1:
return path
var last_normal:Vector3
var point:Vector3
var optimized_list = []
var uniq = []
@Einlander
Einlander / generate_static_collision_tree.gd
Created February 26, 2019 08:17
Simple Godot script to generate Trimesh Collisions on a node and all it's children
#Simple script to generate Trimesh Collisions on a node and all it's children
extends Node
var collision_body = StaticBody.new()
var collision_shape = CollisionShape.new()
func _ready():
walk_nodes(self)
@Einlander
Einlander / fps_histogram.gd
Created December 16, 2018 22:32
Draws a Histogram of your last 300 fps
extends Node2D
# Declare memr variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
var _fps_ticker_data = []
var fpskeydown = false
@Einlander
Einlander / cubemap_capture.gd
Created September 19, 2018 03:39
Takes the needed pictures to create a cube map.
extends Camera
# Takes the needed pictures to create a cube map.
# Read this to find where the files are saved. http://docs.godotengine.org/en/3.0/tutorials/io/data_paths.html?highlight=user%3A%2F%2F
# Go here to make it useable in godot. https://nadirpatch.com/cube2sphere/
var _pass = 0
func _ready():
get_viewport().size = Vector2(1024,1024)
self.rotation = Vector3(0,0,0)
pass
@Einlander
Einlander / scene_debug.gd
Last active February 3, 2021 20:04
A super useful script for fps games. Attach it to the root node in your scene. Provides an FPS counter, fullscreen toggle, exits the game, and reloads the scene.
# Simple Utility Script
# Traps Mouse Cursor and hides it.
# ESCAPE to quit game
# F5 to reload current scene
# F9 to toggle collision shape dispay. Scene MUST be reloaded
# F10 to toggle fps Display
# F11 to switch from windowed to fullscreen
# F12 to take screenshot
#
# Works great for fps games
@Einlander
Einlander / fps_player.gd
Last active January 19, 2022 20:01
Prototype Godot FPS Controller
extends KinematicBody
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
export(float) var walk_speed = 4
export(float) var run_speed = 6
export(float) var acceleration = 5
export(float) var deceleration = 8