Skip to content

Latest commit

History

History
49 lines (39 loc) · 1.46 KB

File metadata and controls

49 lines (39 loc) · 1.46 KB
usingUnity.Mathematics;publicstaticclassInputDeltaUtilities{publicconstfloatInputWrapAroundValue=2000f;publicstaticvoidAddInputDelta(reffloatinput,floataddedDelta){input=math.fmod(input+addedDelta,InputWrapAroundValue);}publicstaticvoidAddInputDelta(reffloat2input,float2addedDelta){input=math.fmod(input+addedDelta,InputWrapAroundValue);}publicstaticfloatGetInputDelta(floatcurrentValue,floatpreviousValue){floatdelta=currentValue-previousValue;// When delta is very large, consider that the input has wrapped aroundif(math.abs(delta)>(InputWrapAroundValue*0.5f)){delta+=(math.sign(previousValue-currentValue)*InputWrapAroundValue);}returndelta;}publicstaticfloat2GetInputDelta(float2currentValue,float2previousValue){float2delta=currentValue-previousValue;// When delta is very large, consider that the input has wrapped aroundif(math.abs(delta.x)>(InputWrapAroundValue*0.5f)){delta.x+=(math.sign(previousValue.x-currentValue.x)*InputWrapAroundValue);}if(math.abs(delta.y)>(InputWrapAroundValue*0.5f)){delta.y+=(math.sign(previousValue.y-currentValue.y)*InputWrapAroundValue);}returndelta;}}