Merge pull request #100 from LeaPhant/add-idle-animation

Add idle animation
This commit is contained in:
Haowei Wen 2021-11-01 00:42:03 +08:00 committed by GitHub
commit 819fdd5c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -134,6 +134,7 @@
<h2>Walk / Run / Fly</h2>
<div class="control">
<label><input type="radio" id="primary_animation_none" name="primary_animation" value="" checked> None</label>
<label><input type="radio" id="primary_animation_idle" name="primary_animation" value="idle"> Idle</label>
<label><input type="radio" id="primary_animation_walk" name="primary_animation" value="walk"> Walk</label>
<label><input type="radio" id="primary_animation_run" name="primary_animation" value="run"> Run</label>
<label><input type="radio" id="primary_animation_fly" name="primary_animation" value="fly"> Fly</label>
@ -284,6 +285,7 @@
const skinParts = ["head", "body", "rightArm", "leftArm", "rightLeg", "leftLeg"];
const skinLayers = ["innerLayer", "outerLayer"];
const availableAnimations = {
idle: skinview3d.IdleAnimation,
walk: skinview3d.WalkingAnimation,
run: skinview3d.RunningAnimation,
fly: skinview3d.FlyingAnimation

View File

@ -133,6 +133,22 @@ export class RootAnimation extends CompositeAnimation implements AnimationHandle
}
}
export const IdleAnimation: Animation = (player, time) => {
const skin = player.skin;
// Multiply by animation's natural speed
time *= 2;
// Arm swing
const basicArmRotationZ = Math.PI * 0.02;
skin.leftArm.rotation.z = Math.cos(time) * 0.03 + basicArmRotationZ;
skin.rightArm.rotation.z = Math.cos(time + Math.PI) * 0.03 - basicArmRotationZ;
// Always add an angle for cape around the x axis
const basicCapeRotationX = Math.PI * 0.06;
player.cape.rotation.x = Math.sin(time) * 0.01 + basicCapeRotationX;
};
export const WalkingAnimation: Animation = (player, time) => {
const skin = player.skin;