From 5da30d215717c7abcf9e73b401567c9fdecdd919 Mon Sep 17 00:00:00 2001 From: LeaPhant Date: Sun, 10 Oct 2021 14:36:54 +0200 Subject: [PATCH 1/2] Add idle animation --- src/animation.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/animation.ts b/src/animation.ts index 8971dd8..49e887f 100644 --- a/src/animation.ts +++ b/src/animation.ts @@ -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; From af85724b2dcc019c5a14d1c6e67aef4ca5ef136d Mon Sep 17 00:00:00 2001 From: LeaPhant Date: Sun, 10 Oct 2021 14:45:34 +0200 Subject: [PATCH 2/2] Add idle animation to example --- examples/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/index.html b/examples/index.html index 27e5e3a..56b15af 100644 --- a/examples/index.html +++ b/examples/index.html @@ -134,6 +134,7 @@

Walk / Run / Fly

+ @@ -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