Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Wave Animation #169

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading