Skip to content

Instantly share code, notes, and snippets.

View devindazzle's full-sized avatar
💭
Writing some delicious spaghetti code

Kim Pedersen devindazzle

💭
Writing some delicious spaghetti code
View GitHub Profile
@devindazzle
devindazzle / SpriteWrapper.cs
Created November 29, 2022 10:56
This component will mirror a sprite renderer and create a sprite wrapping effect at the edges of the screen similar to the game Asteroids. To use the component, add it to the same game object as the sprite renderer you want to mirror and it just works. Optionally, you can set the warp property to true and the game object will warp to the opposit…
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
public class SpriteWrapper : MonoBehaviour {
[Header("Sprite Wrapper")]
[Tooltip("Should sprite be wrapped when reaching the edge of the screen?"), SerializeField]
private bool wrap;
@devindazzle
devindazzle / smoothDamp.swift
Created August 23, 2016 12:07
The smoothDamp function in Unity implemented using Swift
/**
* Gradually changes a value towards a desired goal over time - implemented from Unity C#
*/
public func smoothDamp(current c: CGFloat, target t: CGFloat, currentVelocity: inout CGFloat, smoothTime time: CGFloat, maxSpeed: CGFloat = CGFloat.infinity, deltaTime: CGFloat) -> CGFloat {
let smoothTime = max(0.0001, time)
let num = 2 / smoothTime
let num2 = num * deltaTime
let num3 = 1 / (1 + num2 + 0.48 * num2 * num2 + 0.235 * num2 * num2 * num2)
var num4 = c - t
let num5 = t
@devindazzle
devindazzle / UIImage+Extensions
Created March 11, 2015 13:31
Extension of UIImage to create a new UIImage with a given size and color
extension UIImage {
convenience init?(size: CGSize, color: UIColor) {
// Create a rect for this context
var rect = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height)
// Generate the texture
// Start image context with the given size
UIGraphicsBeginImageContext(size)
@devindazzle
devindazzle / gist:f3b55028fc49f434365d
Created August 13, 2014 16:29
CharacterController2D
using System;
using System.Linq;
using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class CharacterController2D : MonoBehaviour
{
#region Fields and Properties
[Range(.001f, 0.3f)]
public float SkinWidth = .02f;
import Foundation
import UIKit
import SceneKit
import QuartzCore
class MyViewController : UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
- (CGFloat) randomNumberBetween0and1
{
// Generates a random float between 0.0f and 1.0f. Remember to seed using
// srandom(time(0));
return random() / (float)0x7fffffff;
}