Skip to content

Instantly share code, notes, and snippets.

View willnationsdev's full-sized avatar

Will Nations willnationsdev

View GitHub Profile
@willnationsdev
willnationsdev / HoverContainer.gd
Last active July 5, 2017 13:34
HoverContainer: emits a "mouse_hovering" event periodically
extends Container
signal mouse_hovering(position, velocity)
var is_hovering = false
export var hover_emission_rate = 1.0
var hover_accumulator = 0.0
var last_mouse_position = Vector2(0,0)
func _ready():
@willnationsdev
willnationsdev / deletion_guide.gd
Last active July 3, 2017 01:52
Godot Deletion Guide
# Reference in GDScript:
# The refcount is incremented on assign, pass as argument, etc. It's decremented...:
# Members: when the instance is freed.
# Locals: it's a bit weird in this case though. You would expect it to be on scope
# exit like in C++, but it's actually on function return. However, and this
# is the weird part, if there are two locals at the same stack address, the
# refcount is decremented when the latter local is first assigned. e.g.:
func hello_there():
if whatever:
@willnationsdev
willnationsdev / create_enemy_button.gd
Last active July 19, 2017 13:20
GodotTemplate - for creating run-time/design-time scripts dynamically
# Class: CreateEnemyButton
# Author: willnationsdev
# License: MIT
# Description: This class demonstrations a sample use-case for the Template class.
# A button which triggers the creation of enemy scripts when pressed.
# Godot Version: 3.0 pre-alpha
tool
extends Button
@willnationsdev
willnationsdev / test.gd
Last active August 4, 2017 14:52
Answering question 1
extends KinematicBody2D
var direction = Vector2()
var anim = ""
onready var animplayer = getNode("AnimationPlayer")
var velocity = Vector2()
var speed = 0
@willnationsdev
willnationsdev / RigidbodyController3D.gd
Last active February 27, 2024 20:03
A Basic Controller for a 3D Rigidbody in Godot 3.0
# ---
# Note: I honestly can't remember where this gist came from.
# This sounds like something I would've uploaded from sample code people shared on Reddit while asking questions.
# So, as far as my part in sharing this code, I would consider it to be MIT licensed.
# If someone on Reddit suddenly pops up saying I'm not crediting them, then I'll gladly add the credit.
# ---
# A Rigidbody Controller for basic 3D movement
extends RigidBody
@willnationsdev
willnationsdev / area2d_click.gd
Last active October 27, 2017 12:31
Godot 2.1 Multi-Area2D Left Mouse Sprite-Clicking Guide
# Note that this ultimately is the WRONG way to handle this, but I learned some stuff along the way.
# I later discovered that you should just use _unhandled_input and SceneTree.set_input_as_handled, and it'll work perfectly. Figures.
extends Area2D
# Detect the input that has not been handled by ANY other input handlers
# http://docs.godotengine.org/en/stable/learning/features/inputs/inputevent.html
func _input_event(viewport, event, shape_idx):
# Detect a left mouse click
# http://docs.godotengine.org/en/stable/classes/class_inputevent.html
@willnationsdev
willnationsdev / spaceship.gd
Created December 20, 2017 16:41
Simple Spaceship Propellant Motion
# stolen from Discord's igalencar's message in #programming channel
extends KinematicBody2D
const MAX_SPEED = 300
const MAX_FORCE = 0.02
var velocity = Vector2()
onready var target = get_position()
func _ready():
@willnationsdev
willnationsdev / jump_height.gd
Created December 21, 2017 15:40
Specify Jump height in Godot 2D
export var jump_height = 128.0 # px
...
var g = ProjectSettings.get("physics/2d/default_gravity_vector").y * ProjectSettings.get("physics/2d/default_gravity") # px / s ^2
var jump_velocity = sqrt(2 * g * jump_height) # px / s
@willnationsdev
willnationsdev / godot_module_docs.md
Created December 24, 2017 13:59
How to create documentation for a Godot Module

So after fiddling and experimenting, I kinda figured out the workflow of writing custom docs for your custom module :D

  1. Make a new directory doc_classes in the root of your custom module.

  2. Add following code to config.py:

    def get_doc_classes(): return [ "YourClassName", ]

@willnationsdev
willnationsdev / res_utility.gd
Last active December 26, 2017 16:24
Create flat or tiered view dictionaries of directories in Godot Engine.
# A collection of static functions for searching through the res:// directory.
tool
extends Reference
##### CLASSES #####
##### SIGNALS #####
##### CONSTANTS #####