Skip to content

Instantly share code, notes, and snippets.

@timrodz
Forked from jringrose/Extensions_Math.cs
Created November 20, 2018 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timrodz/27aa9c6f7d8a49d8ffa3e8842d7fa758 to your computer and use it in GitHub Desktop.
Save timrodz/27aa9c6f7d8a49d8ffa3e8842d7fa758 to your computer and use it in GitHub Desktop.
using System;
using UnityEngine;
public static class Extensions_Math
{
// ...
public static float VectorToRad(this Vector2 thisVec){
return Mathf.Atan2(thisVec.y, thisVec.x);
}
public static Vector2 RadToVector(this float thisFloat){
return new Vector2(Mathf.Cos(thisFloat), Mathf.Sin(thisFloat));
}
public static float VectorToDeg(this Vector2 thisVec){
return Mathf.Atan2(thisVec.y, thisVec.x) * Mathf.Rad2Deg;
}
public static Vector2 DegToVector(this float thisFloat){
return new Vector2(Mathf.Cos(thisFloat * Mathf.Deg2Rad), Mathf.Sin(thisFloat * Mathf.Deg2Rad));
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment