@@ -23,6 +23,7 @@ public class ArenaManipulation : Modifier
2323 //private Quaternion currentRotation;
2424 public bool Preload { get ; set ; }
2525 public bool Reset { get ; set ; }
26+ public bool ShortestRoute { get ; set ; }
2627 /*protected ArenaManipulation(ModifierType _type, float _startTick, float _endTick, string _amountX, string _amountY, string _amountZ, bool _reset, bool _preload)
2728 {
2829 Type = _type;
@@ -48,14 +49,14 @@ public override void Activate()
4849 //MelonLogger.Msg("Target " + Type.ToString() + ": " + targetAmount.x + "/" + targetAmount.y + "/" + targetAmount.z);
4950 if ( Preload )
5051 {
51- SetAmount ( targetAmount ) ;
52+ SetAmount ( targetAmount , true ) ;
5253 }
5354 else
5455 {
5556 base . Activate ( ) ;
5657 if ( EndTick == StartTick || EndTick == 0 )
5758 {
58- SetAmount ( targetAmount ) ;
59+ SetAmount ( targetAmount , true ) ;
5960 }
6061 else
6162 {
@@ -140,16 +141,18 @@ private void GetTargetAmount()
140141 targetAmount . z = currentAmount . z ;
141142 }
142143
143- if ( Type == ModifierType . ArenaSpin )
144- {
145- float tickSpan = EndTick - StartTick ;
146- if ( Reset ) tickSpan = 1 ;
147- amountPerTick = new Vector3 ( Mathf . DeltaAngle ( currentAmount . x , targetAmount . x ) , Mathf . DeltaAngle ( currentAmount . y , targetAmount . y ) , Mathf . DeltaAngle ( currentAmount . z , targetAmount . z ) ) ;
148- amountPerTick /= tickSpan ;
149- //amountPerTick = (targetAmount - currentAmount) / tickSpan;
150- //MelonLogger.Msg($"{amountPerTick.x}/{amountPerTick.y}/{amountPerTick.z} over {tickSpan} ticks (Target: {targetAmount.x}/{targetAmount.y}/{targetAmount.z} || Calculated: {amountPerTick.x * tickSpan}/{amountPerTick.y * tickSpan}/{amountPerTick.z * tickSpan})");
151- lastTick = StartTick ;
152- }
144+
145+ //if (Type != ModifierType.ArenaScale) targetAmount += currentAmount;
146+ }
147+ if ( Type == ModifierType . ArenaSpin )
148+ {
149+ float tickSpan = EndTick - StartTick ;
150+ if ( Reset || EndTick == 0 || StartTick == EndTick ) tickSpan = 1 ;
151+ //amountPerTick = new Vector3(Mathf.DeltaAngle(currentAmount.x, targetAmount.x), Mathf.DeltaAngle(currentAmount.y, targetAmount.y), Mathf.DeltaAngle(currentAmount.z, targetAmount.z));
152+ //amountPerTick /= tickSpan;
153+ amountPerTick = ( targetAmount - currentAmount ) / tickSpan ;
154+ //MelonLogger.Msg($"{amountPerTick.x}/{amountPerTick.y}/{amountPerTick.z} over {tickSpan} ticks (Target: {targetAmount.x}/{targetAmount.y}/{targetAmount.z} || Calculated: {amountPerTick.x * tickSpan}/{amountPerTick.y * tickSpan}/{amountPerTick.z * tickSpan})");
155+ lastTick = StartTick ;
153156 }
154157 }
155158 private Vector3 amountPerTick = new Vector3 ( ) ;
@@ -168,6 +171,7 @@ protected Vector3 GetAmount(float percentage)
168171 amnt.y = CalculateAmount(currentAmount.y, targetAmount.y, percentage);
169172 amnt.z = CalculateAmount(currentAmount.z, targetAmount.z, percentage);
170173 }*/
174+
171175 amnt . x = CalculateAmount ( currentAmount . x , targetAmount . x , percentage ) ;
172176 amnt . y = CalculateAmount ( currentAmount . y , targetAmount . y , percentage ) ;
173177 amnt . z = CalculateAmount ( currentAmount . z , targetAmount . z , percentage ) ;
@@ -194,16 +198,18 @@ private IEnumerator DoManipulation()
194198 {
195199 float percentage = ( ( AudioDriver . I . mCachedTick - StartTick ) * 100f ) / ( EndTick - StartTick ) ;
196200 percentage /= 100f ;
197- SetAmount ( GetAmount ( percentage ) ) ;
201+ SetAmount ( GetAmount ( percentage ) , false , percentage ) ;
202+ if ( Type == ModifierType . ArenaSpin )
203+ {
204+ //world.rotation = Quaternion.Lerp(Quaternion.Euler(currentAmount), Quaternion.Euler(targetAmount), percentage);
205+
206+ }
198207 yield return new WaitForSecondsRealtime ( Time . unscaledDeltaTime ) ;
199208 }
200209 //if (Type == ModifierType.ArenaSpin) SetAmount(targetRotation);
201- SetAmount ( targetAmount ) ;
210+ SetAmount ( targetAmount , true ) ;
202211 }
203212
204-
205-
206-
207213 private float CalculateAmount ( float current , float target , float percentage )
208214 {
209215 //if(Type == ModifierType.ArenaSpin) target = target * target * (3f - 2f * target); //test this
@@ -216,7 +222,7 @@ private float CalculateAmount(float current, float target, float percentage)
216222 world.transform.rotation = rot;
217223 }*/
218224
219- private void SetAmount ( Vector3 _amount )
225+ private void SetAmount ( Vector3 _amount , bool instant , float percentage = 100f )
220226 {
221227 switch ( Type )
222228 {
@@ -227,9 +233,9 @@ private void SetAmount(Vector3 _amount)
227233 world . transform . localScale = _amount ;
228234 break ;
229235 case ModifierType . ArenaSpin :
230- /* float currentTick = AudioDriver.I.mCachedTick;
236+ float currentTick = AudioDriver . I . mCachedTick ;
231237 float numTicksPassed = currentTick - lastTick ;
232- lastTick = currentTick;*/
238+ lastTick = currentTick ;
233239
234240 /*world.Rotate(Vector3.right, amountPerTick.x * numTicksPassed);
235241 world.Rotate(Vector3.up, amountPerTick.y * numTicksPassed);
@@ -239,14 +245,31 @@ private void SetAmount(Vector3 _amount)
239245 /*world.rotation *= Quaternion.AngleAxis(amountPerTick.x * numTicksPassed, Vector3.right);
240246 world.rotation *= Quaternion.AngleAxis(amountPerTick.y * numTicksPassed, Vector3.up);
241247 world.rotation *= Quaternion.AngleAxis(amountPerTick.z * numTicksPassed, Vector3.forward);*/
242- /*
243- world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
248+
249+ /* world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
244250 world.transform.rotation *= Quaternion.AngleAxis(_amount.y, Vector3.up);
245251 world.transform.rotation *= Quaternion.AngleAxis(_amount.z, Vector3.forward);
246252 */
253+ /*if (instant) world.rotation = Quaternion.Euler(_amount);
254+ else
255+ {
256+
257+ }*/
258+ if ( Reset && instant ) world . rotation = Quaternion . identity ;
259+ else
260+ {
261+ if ( ShortestRoute ) world . rotation = Quaternion . Lerp ( Quaternion . Euler ( currentAmount ) , Quaternion . Euler ( targetAmount ) , percentage ) ;
262+ else world . rotation = Quaternion . Euler ( _amount ) ;
263+ }
247264
248- //world.eulerAngles = _amount;
249- world . rotation = Quaternion . Euler ( _amount ) ;
265+
266+ /*world.rotation *= Quaternion.AngleAxis(amountPerTick.x * numTicksPassed, Vector3.right);
267+ world.rotation *= Quaternion.AngleAxis(amountPerTick.y * numTicksPassed, Vector3.up);
268+ world.rotation *= Quaternion.AngleAxis(amountPerTick.z * numTicksPassed, Vector3.forward);*/
269+
270+
271+ //world.rotation = Quaternion.Euler(_amount);
272+ //MelonLogger.Msg(world.rotation.x + " " + world.rotation.y + " " + world.rotation.z);
250273 //world.localRotation = Quaternion.Euler(_amount);
251274 break ;
252275 default :
0 commit comments