@@ -45,7 +45,7 @@ public override void Activate()
4545 if ( world is null ) return ;
4646 GetCurrentAmount ( ) ;
4747 GetTargetAmount ( ) ;
48-
48+ //MelonLogger.Msg("Target " + Type.ToString() + ": " + targetAmount.x + "/" + targetAmount.y + "/" + targetAmount.z);
4949 if ( Preload )
5050 {
5151 SetAmount ( targetAmount ) ;
@@ -77,6 +77,7 @@ private void GetCurrentAmount()
7777 currentAmount = world . position ;
7878 break ;
7979 case ModifierType . ArenaScale :
80+ //currentAmount = world.localScale;
8081 currentAmount = world . localScale ;
8182 break ;
8283 case ModifierType . ArenaSpin :
@@ -96,49 +97,88 @@ private void GetTargetAmount()
9697 }
9798 else
9899 {
99-
100- if ( float . TryParse ( AmountX , out float _x ) )
100+ if ( AmountX == "" )
101+ {
102+ targetAmount . x = currentAmount . x ;
103+ }
104+ else if ( float . TryParse ( AmountX , out float _x ) )
101105 {
102- targetAmount . x = _x + currentAmount . x ;
106+ //targetAmount.x = _x + (Type == ModifierType.ArenaScale ? 0f : currentAmount.x);
107+ targetAmount . x = _x ;
103108 //parsedX = _x;
104109 }
105110 else
106111 {
107112 targetAmount . x = currentAmount . x ;
108113 }
109- if ( float . TryParse ( AmountY , out float _y ) )
114+ if ( AmountY == "" )
115+ {
116+ targetAmount . y = currentAmount . y ;
117+ }
118+ else if ( float . TryParse ( AmountY , out float _y ) )
110119 {
111- targetAmount . y = _y + currentAmount . y ;
120+ //targetAmount.y = _y + (Type == ModifierType.ArenaScale ? 0f : currentAmount.y);
121+ targetAmount . y = _y ;
112122 //parsedY = _y;
113123 }
114124 else
115125 {
116126 targetAmount . y = currentAmount . y ;
117127 }
118- if ( float . TryParse ( AmountZ , out float _z ) )
128+ if ( AmountZ == "" )
119129 {
120- targetAmount . z = _z + currentAmount . z ;
130+ targetAmount . z = currentAmount . z ;
131+ }
132+ else if ( float . TryParse ( AmountZ , out float _z ) )
133+ {
134+ //targetAmount.z = _z + (Type == ModifierType.ArenaScale ? 0f : currentAmount.z);
135+ targetAmount . z = _z ;
121136 //parsedZ = _z;
122137 }
123138 else
124139 {
125140 targetAmount . z = currentAmount . z ;
126141 }
127142
128- //if (type == ModifierType.ArenaSpin) targetRotation = Quaternion.Euler(targetAmount);
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+ }
129153 }
130154 }
131-
155+ private Vector3 amountPerTick = new Vector3 ( ) ;
156+ private float lastTick ;
132157 protected Vector3 GetAmount ( float percentage )
133158 {
134159
135160 Vector3 amnt ;
161+ /*if(Type == ModifierType.ArenaSpin)
162+ {
163+ amnt = Quaternion.Euler(CalculateRotation(currentAmount, targetAmount, percentage)).eulerAngles;
164+ }
165+ else
166+ {
167+ amnt.x = CalculateAmount(currentAmount.x, targetAmount.x, percentage);
168+ amnt.y = CalculateAmount(currentAmount.y, targetAmount.y, percentage);
169+ amnt.z = CalculateAmount(currentAmount.z, targetAmount.z, percentage);
170+ }*/
136171 amnt . x = CalculateAmount ( currentAmount . x , targetAmount . x , percentage ) ;
137172 amnt . y = CalculateAmount ( currentAmount . y , targetAmount . y , percentage ) ;
138173 amnt . z = CalculateAmount ( currentAmount . z , targetAmount . z , percentage ) ;
139174 return amnt ;
140175 }
141176
177+ protected Vector3 CalculateRotation ( Vector3 current , Vector3 target , float percentage )
178+ {
179+ return Vector3 . Lerp ( current , target , percentage ) ;
180+ }
181+
142182 /*protected Vector3 GetRotation(float percentage)
143183 {
144184 float seconds = AudioDriver.TickSpanToMs(SongDataHolder.I.songData, StartTick, EndTick);
@@ -154,17 +194,20 @@ private IEnumerator DoManipulation()
154194 {
155195 float percentage = ( ( AudioDriver . I . mCachedTick - StartTick ) * 100f ) / ( EndTick - StartTick ) ;
156196 percentage /= 100f ;
157- if ( Type == ModifierType . ArenaSpin ) SetAmount ( GetAmount ( percentage ) ) ;
158- else SetAmount ( GetAmount ( percentage ) ) ;
159-
197+ SetAmount ( GetAmount ( percentage ) ) ;
160198 yield return new WaitForSecondsRealtime ( Time . unscaledDeltaTime ) ;
161199 }
200+ //if (Type == ModifierType.ArenaSpin) SetAmount(targetRotation);
162201 SetAmount ( targetAmount ) ;
163202 }
164203
204+
205+
206+
165207 private float CalculateAmount ( float current , float target , float percentage )
166208 {
167- target = target * target * ( 3f - 2f * target ) ; //test this
209+ //if(Type == ModifierType.ArenaSpin) target = target * target * (3f - 2f * target); //test this
210+
168211 return Mathf . Lerp ( current , target , percentage ) ;
169212 }
170213
@@ -184,16 +227,38 @@ private void SetAmount(Vector3 _amount)
184227 world . transform . localScale = _amount ;
185228 break ;
186229 case ModifierType . ArenaSpin :
187- /*world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
230+ /*float currentTick = AudioDriver.I.mCachedTick;
231+ float numTicksPassed = currentTick - lastTick;
232+ lastTick = currentTick;*/
233+
234+ /*world.Rotate(Vector3.right, amountPerTick.x * numTicksPassed);
235+ world.Rotate(Vector3.up, amountPerTick.y * numTicksPassed);
236+ world.Rotate(Vector3.forward, amountPerTick.z * numTicksPassed);*/
237+ //world.Rotate(amountPerTick * numTicksPassed);
238+
239+ /*world.rotation *= Quaternion.AngleAxis(amountPerTick.x * numTicksPassed, Vector3.right);
240+ world.rotation *= Quaternion.AngleAxis(amountPerTick.y * numTicksPassed, Vector3.up);
241+ world.rotation *= Quaternion.AngleAxis(amountPerTick.z * numTicksPassed, Vector3.forward);*/
242+ /*
243+ world.transform.rotation *= Quaternion.AngleAxis(_amount.x, Vector3.right);
188244 world.transform.rotation *= Quaternion.AngleAxis(_amount.y, Vector3.up);
189- world.transform.rotation *= Quaternion.AngleAxis(_amount.z, Vector3.forward);*/
190- world . eulerAngles = _amount ;
245+ world.transform.rotation *= Quaternion.AngleAxis(_amount.z, Vector3.forward);
246+ */
247+
248+ //world.eulerAngles = _amount;
249+ world . rotation = Quaternion . Euler ( _amount ) ;
250+ //world.localRotation = Quaternion.Euler(_amount);
191251 break ;
192252 default :
193253 break ;
194254 }
195255 }
196256
257+ private void SetAmount ( Quaternion rotation )
258+ {
259+ world . rotation = rotation ;
260+ }
261+
197262 private void ResetArena ( )
198263 {
199264 switch ( Type )
0 commit comments