Skip to content

Commit

Permalink
Added Wave Animation (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknowncall authored Sep 21, 2024
1 parent 32b725d commit cebaa44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h1>Animation</h1>
<label><input type="radio" id="animation_walk" name="animation" value="walk" /> Walk</label>
<label><input type="radio" id="animation_run" name="animation" value="run" /> Run</label>
<label><input type="radio" id="animation_fly" name="animation" value="fly" /> Fly</label>
<label><input type="radio" id="animation_wave" name="animation" value="wave" /> Wave</label>
</div>
<label class="control">Speed: <input id="animation_speed" type="number" value="1" step="0.1" size="3" /></label>
<button id="animation_pause_resume" type="button" class="control">Pause / Resume</button>
Expand Down
1 change: 1 addition & 0 deletions examples/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const availableAnimations = {
walk: new skinview3d.WalkingAnimation(),
run: new skinview3d.RunningAnimation(),
fly: new skinview3d.FlyingAnimation(),
wave: new skinview3d.WaveAnimation(),
};

let skinViewer: skinview3d.SkinViewer;
Expand Down
18 changes: 18 additions & 0 deletions src/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,21 @@ export class FlyingAnimation extends PlayerAnimation {
player.elytra.updateRightWing();
}
}

export class WaveAnimation extends PlayerAnimation {

whichArm: string;

constructor(whichArm: 'left' | 'right' = 'left') {
super();
this.whichArm = whichArm;
}

protected animate(player: PlayerObject): void {
const t = this.progress * 2 * Math.PI * 0.5;

const targetArm = this.whichArm === 'left' ? player.skin.leftArm : player.skin.rightArm;
targetArm.rotation.x = 180
targetArm.rotation.z = Math.sin(t) * 0.5;
}
}

0 comments on commit cebaa44

Please sign in to comment.