Skip to content

Instantly share code, notes, and snippets.


Robert Yang radiatoryang

View GitHub Profile
radiatoryang / FlxSeparateCircle.hx
Last active May 4, 2021
Terrible hack for HaxeFlixel that adds a separation (collision) function for circle-shaped hitboxes... it's a hack, so it just assumes a circular collider of radius = width/2 ... plug this into a custom FlxG.overlap collision call in your main PlayState... also I don't know how to code so sorry lol
View FlxSeparateCircle.hx
public static function separateCircle(circle1:FlxSprite, circle2:FlxSprite):Bool
var totalRadius:Float = circle1.width / 2 + circle2.width / 2;
var c1 = circle1.getMidpoint(FlxPoint.weak());
var c2 = circle2.getMidpoint(FlxPoint.weak());
var distanceSquared:Float = (c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y);
if (distanceSquared < totalRadius * totalRadius)
var overlap:Float = totalRadius - Math.sqrt(distanceSquared);
radiatoryang / AxisInput.cs
Created Nov 13, 2020
Unity C# input code demos for Studio 1, Fall 2020 at NYU Game Center
View AxisInput.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AxisInput : MonoBehaviour
void Update()
// Input Axis is a virtual joystick... unlike GetKey, it returns -1.0 - +1.0
// e.g. holding your joystick to the left: -1.0f
radiatoryang / SmoothVideoPlaylist.cs
Last active Dec 15, 2020
short Unity C# script example for smoothly cutting / playing a playllist of VideoClips, by using one VideoPlayer (activeCam) to play the video and another VideoPlayer (otherCam) to cue up the next video... MIT License.
View SmoothVideoPlaylist.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class SmoothVideoPlaylist : MonoBehaviour {
// to smoothly cut between two videos, we need two VideoPlayers
// make sure you create two VideoPlayers and assign them in the Inspector
public VideoPlayer activeCam, otherCam;
radiatoryang / VertexLit-Retro3D.shader
Created May 13, 2018
yet another retro3D shader for Unity with lower vertex precision / etc... made of parts from and
View VertexLit-Retro3D.shader
// mostly from
// mixed with parts of
// under MIT license by Robert Yang (
Shader "Custom/VertexLit-Retro3D" {
_MainTex("Base (RGB)", 2D) = "white" {}
_Color("Color", Color) = (0.5, 0.5, 0.5, 1)
_GeoRes("Geometric Resolution", Float) = 40
radiatoryang / SkinnedMeshCombiner.cs
Last active Oct 31, 2020
example code for combining SkinnedMeshRenderers at runtime (for optimization reasons usually), which I use in my games for Mixamo Fuse models specifically... PLEASE DON'T ASK ME FOR HELP WITH THIS, this is more for learning purposes, and it's not really an easy-to-use Asset Store thing? also I have a lot of weird hacks specific for my uses... ag…
View SkinnedMeshCombiner.cs
// this code is under MIT License, by Robert Yang + others (credits in comments)
// a lot of this is based on
// but I removed the atlasing stuff because I don't need it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
radiatoryang / SkinnedMeshObjectPreviewExample.cs
Last active Apr 23, 2021
An example of a custom ObjectPreview rendering out a SkinnedMesh for Unity Editor C#... I used it for facial expressions and blendshape editing, you might want to use it for something else. I hereby place it under MIT License. Full write-up here:
View SkinnedMeshObjectPreviewExample.cs
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
[CustomPreview(typeof(YourCustomScriptableObject))] // THIS IS VERY IMPORTANT, this is so the editor knows what this is supposed to be previewing at all
public class SkinnedMeshObjectPreviewExample : ObjectPreview {
PreviewRenderUtility m_PreviewUtility;
radiatoryang / Cat.cs
Last active Mar 31, 2016
Cat and Mouse lab base
View Cat.cs
using UnityEngine;
using System.Collections;
public class Cat : MonoBehaviour {
// declare a public variable, of type Transform, called "mouse"
public Transform mouse;
bool shouldIPlayASound = false;
radiatoryang / VRUtility.cs
Created Mar 4, 2016
a script I give to my Unity VR students that demonstrates a few useful "quality of VR" features for their games -- lowering visual quality for higher framerate, and HMD recentering
View VRUtility.cs
using UnityEngine;
using System.Collections;
using UnityEngine.VR; // you always need this to use special VR functions
public class VRUtility : MonoBehaviour {
// Use this for initialization
public void Start () {
// set render quality to 50%, sacrificing visual quality for higher FPS
radiatoryang / RaycastTargetTrigger.cs
Last active May 29, 2019
a script I give to my Unity VR classes to detect when the player is looking at something... put it on anything with a collider, and it'll know if it's being looked at or not
View RaycastTargetTrigger.cs
using UnityEngine;
using System.Collections;
using UnityEngine.VR; // we need this line here for InputTracking and VRSettings functions
// USAGE: put this on a thing you want the player to look at!
// this code will enable that thing to know if it is being looked at!
[RequireComponent (typeof(Collider)) ] // this thing needs a collider if we should look at it
public class RaycastTargetTrigger : MonoBehaviour {
radiatoryang / ConsoleEntry.prefab
Created Dec 15, 2015 — forked from LordNed/ConsoleEntry.prefab
HTC Vive in-vr Console Viewer. Add the ConsoleLogger script to a gameobject in your scene, and then the UIConsoleViewer to the controller or object you want the console to track. It has a somewhat complicated prefab setup so the prefabs have been attached at the end. I have no idea if you can distribute prefabs this way, so someone gets to find …
View ConsoleEntry.prefab
%YAML 1.1
%TAG !u!,2011:
--- !u!1 &121470
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
- 224: {fileID: 22423080}