Helper Scripts Collection 1.3.1
API documentation for the helper scripts compatible with Unity3D
Public Types | Static Public Member Functions | List of all members
NikosAssets.Helpers.NumericHelper Class Reference

Contains some helpful math operations for Vector3s and Quaternions (and other calculations as well) More...

Public Types

enum  AmountFilter { Irrelevant = 0 , HasNone = 1 , HasSome = 2 }
 

Static Public Member Functions

static bool GetAmountValidation (AmountFilter amountFilter, int amount)
 A helper method useful to filter listviews for example More...
 
static float GetMappedResult (float currentInput, float minInput, float maxInput, float minTarget, float maxTarget)
 Map incoming input values to another value (with that you can keep the same ratio for different dimensions) More...
 
static bool Approx (float a, float b, float approxBuffer)
 A custom approx helper respecting a certain tolerance More...
 
static bool RandomChanceSuccess01 (float chance01)
 Returns true or false at a given chance More...
 
static Quaternion LookAt (Vector3 startingPos, Vector3 targetPos, Vector3 eulerOffset)
 Does the calculations to look at a given target More...
 
static Quaternion ClampRotation (Quaternion q, Vector3 bounds)
 Clamps the given quaternion rotation by the given Vector3 angles for each axis More...
 
static Quaternion ClampRotation (Quaternion q, Vector2 boundsX, Vector2 boundsY, Vector2 boundsZ)
 Clamps the given quaternion rotation by the given Vector2 minmax angles for each axis More...
 
static Quaternion ConvertGlobalToLocalRotation (Quaternion globalRotationToConvert, Transform forTransform)
 Converts the given global quat to a local one relative to the given forTransform More...
 
static void CalculateTorqueRotationAlignment (Transform transform, Rigidbody rigidbody, Vector3 direction, float alignmentSpeed, float alignmentDamping)
 Roly-poly like behaviour for a rigidbody More...
 
static float DistanceSquared (Vector3 a, Vector3 b)
 More lightweight distance calculation than Unity's internal Vector3.Vector3.Distance calculation More...
 
static bool IsInAreaDist (Vector3 a, Vector3 b, Vector2 minMaxDistanceInclusive)
 Is the distance between a and b (not squared) in the bounds of minMaxDistanceInclusive ? More...
 
static bool IsInAreaDist (float dist, Vector2 minMaxDistanceInclusive)
 Is the dist (not squared) in the bounds of minMaxDistanceInclusive ? More...
 
static bool IsInAreaDistSquared (Vector3 a, Vector3 b, Vector2 minMaxDistanceNotSquaredInclusive)
 Is the distance between a and b (squared) in the bounds of minMaxDistanceNotSquaredInclusive ? More...
 
static bool IsInAreaDistSquared (float distSquared, Vector2 minMaxDistanceNotSquaredInclusive)
 Is the distSquared (squared) in the bounds of minMaxDistanceNotSquaredInclusive ? More...
 
static bool IsInViewArea3D (Vector3 originPos, Vector3 originNormal, Vector3 targetPos, float maxAngle)
 Checks if the (targetPos - originPos ) Vector3 direction is within the given maxAngle , taking the originNormal into account More...
 
static bool IsInViewHorAndVertBounds (Transform origin, Vector3 targetPos, float verticalMaxAngle, float horizontalMaxAngle)
 Checks if the targetPos is within the horizontal and vertical angle bounds of the origin (caster) More...
 
static Vector4 Divide2Vectors (Vector4 dividend, Vector4 divisor)
 Returns a Vector4 division for each value of the given vectors More...
 
static Vector3 Divide2Vectors (Vector3 dividend, Vector3 divisor)
 Returns a Vector3 division for each value of the given vectors More...
 
static Vector2 Divide2Vectors (Vector2 dividend, Vector2 divisor)
 Returns a Vector2 division for each value of the given vectors More...
 
static float VectorFacingDotResult (Vector3 dir, Vector3 directionToCheck)
 

Detailed Description

Contains some helpful math operations for Vector3s and Quaternions (and other calculations as well)

Member Function Documentation

◆ Approx()

static bool NikosAssets.Helpers.NumericHelper.Approx ( float  a,
float  b,
float  approxBuffer 
)
static

A custom approx helper respecting a certain tolerance

Parameters
a
b
approxBuffer
Returns

◆ CalculateTorqueRotationAlignment()

static void NikosAssets.Helpers.NumericHelper.CalculateTorqueRotationAlignment ( Transform  transform,
Rigidbody  rigidbody,
Vector3  direction,
float  alignmentSpeed,
float  alignmentDamping 
)
static

Roly-poly like behaviour for a rigidbody

Parameters
transformThe transform associated with the rigidbody
rigidbodyThe Rigidbody we want to align
directionThe direction to align to
alignmentSpeedHow fast should the rigidbody jump up
alignmentDampingThe lower this value, the more the rigidbody can overshoot

◆ ClampRotation() [1/2]

static Quaternion NikosAssets.Helpers.NumericHelper.ClampRotation ( Quaternion  q,
Vector2  boundsX,
Vector2  boundsY,
Vector2  boundsZ 
)
static

Clamps the given quaternion rotation by the given Vector2 minmax angles for each axis

Parameters
qThe rotation to clamp
boundsX
boundsY
boundsZ
Returns
A clamped Quaternion rotation

◆ ClampRotation() [2/2]

static Quaternion NikosAssets.Helpers.NumericHelper.ClampRotation ( Quaternion  q,
Vector3  bounds 
)
static

Clamps the given quaternion rotation by the given Vector3 angles for each axis

Parameters
qThe rotation to clamp
boundsThe x,y,z axis to clamp the rotation
Returns
A clamped Quaternion rotation

◆ ConvertGlobalToLocalRotation()

static Quaternion NikosAssets.Helpers.NumericHelper.ConvertGlobalToLocalRotation ( Quaternion  globalRotationToConvert,
Transform  forTransform 
)
static

Converts the given global quat to a local one relative to the given forTransform

Parameters
globalRotationToConvert
forTransform
Returns

◆ DistanceSquared()

static float NikosAssets.Helpers.NumericHelper.DistanceSquared ( Vector3  a,
Vector3  b 
)
static

More lightweight distance calculation than Unity's internal Vector3.Vector3.Distance calculation

Parameters
a
b
Returns
The squared distance

◆ Divide2Vectors() [1/3]

static Vector2 NikosAssets.Helpers.NumericHelper.Divide2Vectors ( Vector2  dividend,
Vector2  divisor 
)
static

Returns a Vector2 division for each value of the given vectors

Parameters
dividend
divisor
Returns
The item by item divided Vector2

◆ Divide2Vectors() [2/3]

static Vector3 NikosAssets.Helpers.NumericHelper.Divide2Vectors ( Vector3  dividend,
Vector3  divisor 
)
static

Returns a Vector3 division for each value of the given vectors

Parameters
dividend
divisor
Returns
The item by item divided Vector3

◆ Divide2Vectors() [3/3]

static Vector4 NikosAssets.Helpers.NumericHelper.Divide2Vectors ( Vector4  dividend,
Vector4  divisor 
)
static

Returns a Vector4 division for each value of the given vectors

Parameters
dividend
divisor
Returns
The item by item divided Vector4

◆ GetAmountValidation()

static bool NikosAssets.Helpers.NumericHelper.GetAmountValidation ( AmountFilter  amountFilter,
int  amount 
)
static

A helper method useful to filter listviews for example

Parameters
amountFilter
amount
Returns

◆ GetMappedResult()

static float NikosAssets.Helpers.NumericHelper.GetMappedResult ( float  currentInput,
float  minInput,
float  maxInput,
float  minTarget,
float  maxTarget 
)
static

Map incoming input values to another value (with that you can keep the same ratio for different dimensions)

Parameters
currentInput
minInput
maxInput
minTarget
maxTarget
Returns
The mapped result

◆ IsInAreaDist() [1/2]

static bool NikosAssets.Helpers.NumericHelper.IsInAreaDist ( float  dist,
Vector2  minMaxDistanceInclusive 
)
static

Is the dist (not squared) in the bounds of minMaxDistanceInclusive ?

Parameters
dist
minMaxDistanceInclusive
Returns
Inbounds = true, otherwise false

◆ IsInAreaDist() [2/2]

static bool NikosAssets.Helpers.NumericHelper.IsInAreaDist ( Vector3  a,
Vector3  b,
Vector2  minMaxDistanceInclusive 
)
static

Is the distance between a and b (not squared) in the bounds of minMaxDistanceInclusive ?

Parameters
a
b
minMaxDistanceInclusive
Returns
Inbounds = true, otherwise false

◆ IsInAreaDistSquared() [1/2]

static bool NikosAssets.Helpers.NumericHelper.IsInAreaDistSquared ( float  distSquared,
Vector2  minMaxDistanceNotSquaredInclusive 
)
static

Is the distSquared (squared) in the bounds of minMaxDistanceNotSquaredInclusive ?

Parameters
distSquared
minMaxDistanceNotSquaredInclusive
Returns
Inbounds = true, otherwise false

◆ IsInAreaDistSquared() [2/2]

static bool NikosAssets.Helpers.NumericHelper.IsInAreaDistSquared ( Vector3  a,
Vector3  b,
Vector2  minMaxDistanceNotSquaredInclusive 
)
static

Is the distance between a and b (squared) in the bounds of minMaxDistanceNotSquaredInclusive ?

Parameters
a
b
minMaxDistanceNotSquaredInclusive
Returns
Inbounds = true, otherwise false

◆ IsInViewArea3D()

static bool NikosAssets.Helpers.NumericHelper.IsInViewArea3D ( Vector3  originPos,
Vector3  originNormal,
Vector3  targetPos,
float  maxAngle 
)
static

Checks if the (targetPos - originPos ) Vector3 direction is within the given maxAngle , taking the originNormal into account

Parameters
originPos
originNormal
targetPos
maxAngle
Returns
True if within angle, otherwise false

◆ IsInViewHorAndVertBounds()

static bool NikosAssets.Helpers.NumericHelper.IsInViewHorAndVertBounds ( Transform  origin,
Vector3  targetPos,
float  verticalMaxAngle,
float  horizontalMaxAngle 
)
static

Checks if the targetPos is within the horizontal and vertical angle bounds of the origin (caster)

Parameters
origin
targetPos
verticalMaxAngle
horizontalMaxAngle
Returns
True if within angle, otherwise false

◆ LookAt()

static Quaternion NikosAssets.Helpers.NumericHelper.LookAt ( Vector3  startingPos,
Vector3  targetPos,
Vector3  eulerOffset 
)
static

Does the calculations to look at a given target

Parameters
startingPos
targetPos
eulerOffset
Returns
The Quaternion rotation to look at the targetPos

◆ RandomChanceSuccess01()

static bool NikosAssets.Helpers.NumericHelper.RandomChanceSuccess01 ( float  chance01)
static

Returns true or false at a given chance

Parameters
chance01Represents the chance in percentage (0 = 0%, 1 = 100%)
Returns
rand = 0,8; chance = 0,9 -> safe | rand = 0,6; chance = 0,5 -> fail | rand = 0,2; chance = 0,5 -> safe |

◆ VectorFacingDotResult()

static float NikosAssets.Helpers.NumericHelper.VectorFacingDotResult ( Vector3  dir,
Vector3  directionToCheck 
)
static

Parameters
dir
directionToCheck
Returns

Returns the dot float result, indicating if the Vector dir is facing the directionToCheck Vector.

dot = 1 => Is Not Facing ("100%" Opposite direction) dot = .5f => Is not Facing dot == 0 => Is Perpendicular dot = -.5f => Is Facing dot = -1 => Is Facing directly "100%"