Let's "Un-Stiff" the Avatar
Use this code:
//Add clock var clock = new THREE.Clock(true);
function animate() { requestAnimationFrame(animate); //add walk walk(); //end add walk acrobatics(); renderer.render(scene, camera); } animate();
// walking function. Let's get lazy //var is_moving_right, is_moving_left, is_moving_forward, is_moving_back; //function isWalking() //{ // if (is_moving_right) return true; // if (is_moving_left) return true; // if (is_moving_forward) return true; // if (is_moving_backward) return true; // return false; //}
function walk() { // if (!isWalking()) return; var position = Math.sin(clock.getElapsedTime() * 10) * 100; right_hand.position.z = position; left_hand.position.z = -position; right_foot.position.z = -position; left_foot.position.z = position; }
var is_cartwheeling = false; var is_flipping = false; var is_turning = false;
function acrobatics() { if (is_cartwheeling) { avatar.rotation.z = avatar.rotation.z + 0.05; } if (is_flipping) { avatar.rotation.x = avatar.rotation.x + 0.05; } if (is_turning) { avatar.rotation.y = avatar.rotation.y + -0.05; } }