37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace BitStrap
|
|
{
|
|
public static class VectorHelper
|
|
{
|
|
public static Vector2 UnitRotateTowards(Vector2 current, Vector2 target, float maxRadiansDelta)
|
|
{
|
|
float current2 = Mathf.Atan2(current.y, current.x) * 57.29578f;
|
|
float target2 = Mathf.Atan2(target.y, target.x) * 57.29578f;
|
|
float f = Mathf.MoveTowardsAngle(current2, target2, maxRadiansDelta * 57.29578f) * ((float)Math.PI / 180f);
|
|
return new Vector2(Mathf.Cos(f), Mathf.Sin(f));
|
|
}
|
|
|
|
public static bool IsBetweenVectors(Vector3 direction, Vector3 lowerBound, Vector3 upperBound)
|
|
{
|
|
return IsOnVectorSide(direction, lowerBound, upperBound) && IsOnVectorSide(direction, upperBound, lowerBound);
|
|
}
|
|
|
|
public static bool IsOnVectorSide(Vector3 direction, Vector3 vector, Vector3 sidePivot)
|
|
{
|
|
return Vector3.Dot(Vector3.Cross(vector, direction), Vector3.Cross(vector, sidePivot)) > 0f;
|
|
}
|
|
|
|
public static bool IsZero(this Vector3 vec)
|
|
{
|
|
return vec.sqrMagnitude <= 0.001f;
|
|
}
|
|
|
|
public static bool IsZero(this Vector2 vec)
|
|
{
|
|
return vec.sqrMagnitude <= 0.001f;
|
|
}
|
|
}
|
|
}
|