Skip to content

Instantly share code, notes, and snippets.

View jeffvella's full-sized avatar
🏠
Working from home

Jeffrey Vella jeffvella

🏠
Working from home
  • Montréal, Canada
View GitHub Profile
@jeffvella
jeffvella / MoveWorldToScreen.cs
Created February 21, 2018 16:00
Unity: Move a world object to the location of an interface element with some spiraling.
using Helpers.Extensions;
using UnityEngine;
public class MoveWorldToScreen : MonoBehaviour
{
private float _distanceTravelled;
private float _magnitude;
private float _totalDistance;
private float _progress;
private Vector3 _startPosition;
@jeffvella
jeffvella / UnityHealthbarOffset.txt
Last active March 1, 2018 16:46
Offset world canvas for perspective camera.
/// <summary>
/// Counteract the perspective camera effects and place healthbar on top of enemey
/// </summary>
private void FixHealthPosition()
{
var screenHealthBarPosition = Camera.main.WorldToScreenPoint(HealthBarCanvas.transform.position);
var screenEnemyPosition = Camera.main.WorldToScreenPoint(transform.position);
HealthContainer.rectTransform.anchoredPosition = new Vector2(screenEnemyPosition.x - screenHealthBarPosition.x, 0);
}
@jeffvella
jeffvella / UnityDrawStringDebugText
Created August 2, 2018 13:34
Drawing Debug text with background in Unity
public static void DrawString(string text, Vector3 worldPos, Color? textColor = null, Color? backColor = null)
{
UnityEditor.Handles.BeginGUI();
var restoreTextColor = GUI.color;
var restoreBackColor = GUI.backgroundColor;
GUI.color = textColor ?? Color.white;
GUI.backgroundColor = backColor ?? Color.black;
var view = UnityEditor.SceneView.currentDrawingSceneView;
@jeffvella
jeffvella / EntitiesViewer.cs
Created August 17, 2018 16:13
Monobehavior for use with Svelto ECS and Odin Inspectors to explore entity data.
using System;
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Svelto.ECS;
using Svelto.ECS.Example.Survive;
using Svelto.ECS.Internal;
using UnityEngine;
public class EntitiesViewer : MonoBehaviour
@jeffvella
jeffvella / SnapToPlatform.cs
Created December 28, 2018 15:05
Attach an object to a platform when they collide and move with it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SnapToPlatform : MonoBehaviour
{
private Vector3 _lastPlatformPosition;
private Quaternion _lastPlatformRotation;
public bool IsOnPlatform;
@jeffvella
jeffvella / InvertSelection.cs
Created January 3, 2019 12:47
Invert the current Unity project / assets selection
using System;
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Object = UnityEngine.Object;
public class InvertSelection : ScriptableWizard
{
[MenuItem("Assets/Selection/Invert", false, 50)]
@jeffvella
jeffvella / NativeArray2D.cs
Created January 18, 2019 13:24
Wrapper around Unity3D's NativeArray<T> with 2D indexer.
using System;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using System.Collections;
namespace Unity.Collections
{
public struct NativeArray2D<T> : IDisposable, IEnumerable<T> where T : unmanaged
{
public NativeArray<T> Internal;
@jeffvella
jeffvella / NativeArray3D.cs
Created January 18, 2019 13:25
Wrapper around Unity3D's NativeArray<T> with 3D indexer.
using System;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using System.Collections;
namespace Unity.Collections
{
public struct NativeArray3D<T> : IDisposable, IEnumerable<T> where T : unmanaged
{
public NativeArray<T> Internal;
@jeffvella
jeffvella / GridNodeOperations.cs
Created January 18, 2019 21:22
Pattern for creating helper Unity Burst jobs
using System;
using Providers.Grid;
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
public static class GridNodeOperations
@jeffvella
jeffvella / _GJK.md
Created February 27, 2019 15:17 — forked from vurtun/_GJK.md
3D Gilbert–Johnson–Keerthi (GJK) distance algorithm

Gilbert–Johnson–Keerthi (GJK) 3D distance algorithm

The Gilbert–Johnson–Keerthi (GJK) distance algorithm is a method of determining the minimum distance between two convex sets. The algorithm's stability, speed which operates in near-constant time, and small storage footprint make it popular for realtime collision detection.

Unlike many other distance algorithms, it has no requirments on geometry data to be stored in any specific format, but instead relies solely on a support function to iteratively generate closer simplices to the correct answer using the Minkowski sum (CSO) of two convex shapes.