Skip to content

Commit cebaa44

Browse files
authored
Added Wave Animation (#169)
1 parent 32b725d commit cebaa44

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

examples/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ <h1>Animation</h1>
5454
<label><input type="radio" id="animation_walk" name="animation" value="walk" /> Walk</label>
5555
<label><input type="radio" id="animation_run" name="animation" value="run" /> Run</label>
5656
<label><input type="radio" id="animation_fly" name="animation" value="fly" /> Fly</label>
57+
<label><input type="radio" id="animation_wave" name="animation" value="wave" /> Wave</label>
5758
</div>
5859
<label class="control">Speed: <input id="animation_speed" type="number" value="1" step="0.1" size="3" /></label>
5960
<button id="animation_pause_resume" type="button" class="control">Pause / Resume</button>

examples/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const availableAnimations = {
88
walk: new skinview3d.WalkingAnimation(),
99
run: new skinview3d.RunningAnimation(),
1010
fly: new skinview3d.FlyingAnimation(),
11+
wave: new skinview3d.WaveAnimation(),
1112
};
1213

1314
let skinViewer: skinview3d.SkinViewer;

src/animation.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,21 @@ export class FlyingAnimation extends PlayerAnimation {
190190
player.elytra.updateRightWing();
191191
}
192192
}
193+
194+
export class WaveAnimation extends PlayerAnimation {
195+
196+
whichArm: string;
197+
198+
constructor(whichArm: 'left' | 'right' = 'left') {
199+
super();
200+
this.whichArm = whichArm;
201+
}
202+
203+
protected animate(player: PlayerObject): void {
204+
const t = this.progress * 2 * Math.PI * 0.5;
205+
206+
const targetArm = this.whichArm === 'left' ? player.skin.leftArm : player.skin.rightArm;
207+
targetArm.rotation.x = 180
208+
targetArm.rotation.z = Math.sin(t) * 0.5;
209+
}
210+
}

0 commit comments

Comments
 (0)