Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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")
# 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
# 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