Skip to content

Instantly share code, notes, and snippets.

View ashblue's full-sized avatar

Ash Blue ashblue

View GitHub Profile
@ashblue
ashblue / move-point-at-angle.js
Created October 9, 2012 17:12
Move point at an angle
/**
* Moves a vertex at an angle for a specific distance, 0 degrees points up and 180 degrees points down
* @param {array} point Location on a cartesian graph formatted as [x, y]
* @param {number} angle Angle at which a point should move in radians
* @param {number} distance How far should the point move at the given angle in pixels?
* @returns {array} Newly moved point formatted as [x, y]
*/
function movePointAtAngle (point, angle, distance) {
return [
point[0] + (Math.sin(angle) * distance),
@ashblue
ashblue / AutoParent.py
Created December 24, 2023 04:18
Automatically parent bones in Blender 3D to objects matching the pattern. Useful for rigging robots and mechanical skeletons.
import bpy
def parent_object_to_bone_by_name(armature, obj):
# Remove the 'O' prefix from the object's name to find the corresponding bone
bone_name = obj.name[1:] if obj.name.startswith("O") else None
if bone_name and bone_name in armature.pose.bones:
target_bone = armature.pose.bones[bone_name]
# Store the original world matrix of the object
@ashblue
ashblue / JumpThrough.cs
Last active September 1, 2023 09:35
Unity 2D jump through platforms with fall support.
using UnityEngine;
using System.Collections;
public class Platform : MonoBehaviour {
SpriteRenderer playerGraphic;
Rigidbody2D playerBody;
BoxCollider2D playerBox;
CircleCollider2D playerCircle;
float padTop = -0.2f; // Padding applied to the top of feet platform checks (prevents player from barely standing on platform)
@ashblue
ashblue / normalize-slope.cs
Last active March 16, 2023 20:08
Unity 2D slope normalizer for walking up and downhill with corner snapping. Based upon https://www.youtube.com/watch?v=xMhgxUFKakQ
// @NOTE Must be called from FixedUpdate() to work properly
void NormalizeSlope () {
// Attempt vertical normalization
if (grounded) {
RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, 1f, whatIsGround);
if (hit.collider != null && Mathf.Abs(hit.normal.x) > 0.1f) {
Rigidbody2D body = GetComponent<Rigidbody2D>();
// Apply the opposite force against the slope force
// You will need to provide your own slopeFriction to stabalize movement
@ashblue
ashblue / Parallax.cs
Last active November 21, 2022 05:49
Unity parallaxing script example
using UnityEngine;
using System.Collections;
// For usage apply the script directly to the element you wish to apply parallaxing
// Based on Brackeys 2D parallaxing script http://brackeys.com/
public class Parallax : MonoBehaviour {
Transform cam; // Camera reference (of its transform)
Vector3 previousCamPos;
public float distanceX = 0f; // Distance of the item (z-index based)
@ashblue
ashblue / HealthManager.cs
Created June 12, 2015 14:02
Unity health management component.
using UnityEngine;
using System.Collections;
namespace Adnc.Combat {
[System.Serializable]
public class StatHealth {
[Tooltip("Set health manually")]
[SerializeField] int health;
int healthMax;
@ashblue
ashblue / docker-compose.mongo.yml
Created January 6, 2018 23:31
Docker Compose example for MongoDB databases. Includes named volume support.
version: '3'
services:
mongodb:
image: mongo:3.6.1
container_name: uv-mongodb
volumes:
- mongodb:/data/db
- mongodb_config:/data/configdb
ports:
- 27017:27017
@ashblue
ashblue / drawer-fix.coffee
Last active March 26, 2021 16:59
From http://localhost/visa-signature/apply.jsp
DRAWER_CONTAINER = 'offer-drawer'
# Remove the drawer if the CSS class changes
_isMobileClass = false
$(window).resize(->
mobileOn = $HTML.hasClass('mobile')
# Change detected, clear the existing class
if mobileOn != _isMobileClass
_isMobileClass = mobileOn
@ashblue
ashblue / unity-repeat-sprite.cs
Created July 23, 2014 15:55
Unity 2d repeating sprite
using UnityEngine;
using System.Collections;
// @NOTE the attached sprite's position should be "top left" or the children will not align properly
// Strech out the image as you need in the sprite render, the following script will auto-correct it
[RequireComponent (typeof (SpriteRenderer))]
// Generates a nice set of repeated sprites inside a streched sprite renderer
// @NOTE Vertical only, you can easily expand this to horizontal with a little tweaking
public class RepeatSpriteBoundary : MonoBehaviour {
@ashblue
ashblue / TriggerEvents.cs
Created October 15, 2019 01:39
A modular wrapper for Unity Triggers that makes them trigger events for enter and exit.
using Adnc.Utility;
using UnityEngine;
using UnityEngine.Events;
namespace CleverCrow.DungeonsAndHumans.Explorations {
public class TriggerEvents : MonoBehaviour {
private TriggerEventsInternal _internal;
[SerializeField]
private string _tag;