This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends KinematicBody2D | |
var direction = Vector2() | |
var anim = "" | |
onready var animplayer = getNode("AnimationPlayer") | |
var velocity = Vector2() | |
var speed = 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
NewerOlder