@@ -208,3 +208,113 @@ export class WaveAnimation extends PlayerAnimation {
208
208
targetArm . rotation . z = Math . sin ( t ) * 0.5 ;
209
209
}
210
210
}
211
+ export class CrouchAnimation extends PlayerAnimation {
212
+ /**
213
+ * Whether to show the progress of animation.
214
+ * Because there is no progress in the crouch animation in Minecraft, the default value here is false.
215
+ * @defaultValue `false`
216
+ */
217
+ showProgress : boolean = false ;
218
+ /**
219
+ * Whether to run this animation once.
220
+ *
221
+ * @defaultValue `false`
222
+ */
223
+ runOnce : boolean = false ;
224
+
225
+ private isRunningHitAnimation : boolean = false ;
226
+ private hitAnimationSpeed : number = 1 ;
227
+ /**
228
+ * Add the hit animation.
229
+ *
230
+ * @param speed - The speed of hit animation and the default is follow the speed of CrouchAnimation.But if the speed of CrouchAnimation is 0,this animation will not run.
231
+ */
232
+ addHitAnimation ( speed : number = this . speed ) : void {
233
+ this . isRunningHitAnimation = true ;
234
+ this . hitAnimationSpeed = speed ;
235
+ }
236
+ private erp : number = 0 ; //elytra rotate progress
237
+ private isCrouched : any ;
238
+ protected animate ( player : PlayerObject ) : void {
239
+ let pr = this . progress * 8 ;
240
+ if ( pr === 0 ) {
241
+ this . isCrouched = undefined ;
242
+ }
243
+ if ( this . runOnce ) {
244
+ pr = clamp ( pr , - 1 , 1 ) ;
245
+ }
246
+ if ( ! this . showProgress ) {
247
+ pr = Math . floor ( pr ) ;
248
+ }
249
+ player . skin . body . rotation . x = 0.4537860552 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
250
+ player . skin . body . position . z =
251
+ 1.3256181 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) - 3.4500310377 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
252
+ player . skin . body . position . y = - 6 - 2.103677462 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
253
+ player . cape . position . y = 8 - 1.851236166577372 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
254
+ player . cape . rotation . x = ( 10.8 * Math . PI ) / 180 + 0.294220265771 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
255
+ player . cape . position . z =
256
+ - 2 + 3.786619432 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) - 3.4500310377 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
257
+ player . elytra . position . x = player . cape . position . x ;
258
+ player . elytra . position . y = player . cape . position . y ;
259
+ player . elytra . position . z = player . cape . position . z ;
260
+ player . elytra . rotation . x = player . cape . rotation . x - ( 10.8 * Math . PI ) / 180 ;
261
+ const pr1 = this . progress / this . speed ;
262
+ if ( Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) === 1 ) {
263
+ this . erp = ! this . isCrouched ? pr1 : this . erp ;
264
+ this . isCrouched = true ;
265
+ player . elytra . leftWing . rotation . z =
266
+ 0.26179944 + 0.4582006 * Math . abs ( Math . sin ( ( Math . min ( pr1 - this . erp , 1 ) * Math . PI ) / 2 ) ) ;
267
+ player . elytra . updateRightWing ( ) ;
268
+ } else if ( this . isCrouched !== undefined ) {
269
+ this . erp = this . isCrouched ? pr1 : this . erp ;
270
+ player . elytra . leftWing . rotation . z =
271
+ 0.72 - 0.4582006 * Math . abs ( Math . sin ( ( Math . min ( pr1 - this . erp , 1 ) * Math . PI ) / 2 ) ) ;
272
+ player . elytra . updateRightWing ( ) ;
273
+ this . isCrouched = false ;
274
+ }
275
+ player . skin . head . position . y = - 3.618325234674 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
276
+ player . skin . leftArm . position . z =
277
+ 3.618325234674 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) - 3.4500310377 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
278
+ player . skin . rightArm . position . z = player . skin . leftArm . position . z ;
279
+ player . skin . leftArm . rotation . x = 0.410367746202 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
280
+ player . skin . rightArm . rotation . x = player . skin . leftArm . rotation . x ;
281
+ player . skin . leftArm . rotation . z = 0.1 ;
282
+ player . skin . rightArm . rotation . z = - player . skin . leftArm . rotation . z ;
283
+ player . skin . leftArm . position . y = - 2 - 2.53943318 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
284
+ player . skin . rightArm . position . y = player . skin . leftArm . position . y ;
285
+ player . skin . rightLeg . position . z = - 3.4500310377 * Math . abs ( Math . sin ( ( pr * Math . PI ) / 2 ) ) ;
286
+ player . skin . leftLeg . position . z = player . skin . rightLeg . position . z ;
287
+ if ( this . isRunningHitAnimation ) {
288
+ const pr2 = this . progress ;
289
+ let t = ( this . progress * 18 * this . hitAnimationSpeed ) / this . speed ;
290
+ if ( this . speed == 0 ) {
291
+ t = 0 ;
292
+ }
293
+ const isCrouching = Math . abs ( Math . sin ( ( pr2 * Math . PI ) / 2 ) ) === 1 ;
294
+ player . skin . rightArm . rotation . x =
295
+ - 0.4537860552 + 2 * Math . sin ( t + Math . PI ) * 0.3 - ( isCrouching ? 0.4537860552 : 0 ) ;
296
+ const basicArmRotationZ = 0.01 * Math . PI + 0.06 ;
297
+ player . skin . rightArm . rotation . z = - Math . cos ( t ) * 0.403 + basicArmRotationZ ;
298
+ player . skin . body . rotation . y = - Math . cos ( t ) * 0.06 ;
299
+ player . skin . leftArm . rotation . x = Math . sin ( t + Math . PI ) * 0.077 + ( isCrouching ? 0.47 : 0 ) ;
300
+ player . skin . leftArm . rotation . z = - Math . cos ( t ) * 0.015 + 0.13 - ( ! isCrouching ? 0.05 : 0 ) ;
301
+ if ( ! isCrouching ) {
302
+ player . skin . leftArm . position . z = Math . cos ( t ) * 0.3 ;
303
+ player . skin . leftArm . position . x = 5 - Math . cos ( t ) * 0.05 ;
304
+ }
305
+ }
306
+ }
307
+ }
308
+ export class HitAnimation extends PlayerAnimation {
309
+ protected animate ( player : PlayerObject ) : void {
310
+ const t = this . progress * 18 ;
311
+ player . skin . rightArm . rotation . x = - 0.4537860552 * 2 + 2 * Math . sin ( t + Math . PI ) * 0.3 ;
312
+ const basicArmRotationZ = 0.01 * Math . PI + 0.06 ;
313
+ player . skin . rightArm . rotation . z = - Math . cos ( t ) * 0.403 + basicArmRotationZ ;
314
+ player . skin . body . rotation . y = - Math . cos ( t ) * 0.06 ;
315
+ player . skin . leftArm . rotation . x = Math . sin ( t + Math . PI ) * 0.077 ;
316
+ player . skin . leftArm . rotation . z = - Math . cos ( t ) * 0.015 + 0.13 - 0.05 ;
317
+ player . skin . leftArm . position . z = Math . cos ( t ) * 0.3 ;
318
+ player . skin . leftArm . position . x = 5 - Math . cos ( t ) * 0.05 ;
319
+ }
320
+ }
0 commit comments