renderer.render(scene, camera);
}
animate();
functionwalk() {
if(!isWalking())return;
varposition = Math.sin(clock.getElapsedTime()*5) * 50;
right_hand.position.z = position;
left_hand.position.z = -position;
right_foot.position.z = -position;
left_foot.position.z = position;
}
varis_cartwheeling = false;
varis_flipping = false;
functionacrobatics() {
if(is_cartwheeling) {
avatar.rotation.z = avatar.rotation.z + 0.05;
}
if(is_flipping) {
avatar.rotation.x = avatar.rotation.x + 0.05;
}
}
varis_moving_right, is_moving_left, is_moving_forward, is_moving_back;
functionisWalking() {
if(is_moving_right)returntrue;
if(is_moving_left)returntrue;
if(is_moving_forward)returntrue;
if(is_moving_back)returntrue;
returnfalse;
}
document.addEventListener('keydown',function(event) {
varcode = event.keyCode;
if(code == 37) { // left
marker.position.x = marker.position.x-5;
is_moving_left = true;
}
if(code == 38) { // up
marker.position.z = marker.position.z-5;
is_moving_forward = true;
}
if(code == 39) { // right
marker.position.x = marker.position.x+5;
is_moving_right = true;
}
if(code == 40) { // down
marker.position.z = marker.position.z+5;
report erratum • discuss
Code: Moving Hands and Feet • 225
Prepared exclusively for Michael Powell