Skip to content

Instantly share code, notes, and snippets.

@ybigus
Created February 11, 2014 21:52
Show Gist options
  • Save ybigus/8944939 to your computer and use it in GitHub Desktop.
Save ybigus/8944939 to your computer and use it in GitHub Desktop.
function moveHero(){
heroWrap.setLinearVelocity(
new THREE.Vector3(0, 0, 0)
);
heroWrap.__dirtyPosition = true;
if(moveTop){
heroWrap.position.x += Math.cos( hero.rotation.y) ;
heroWrap.position.z -= Math.sin( hero.rotation.y) ;
if(currentAnimation!='run')
hero.playAnimation( 'run', 6 );
currentAnimation = 'run';
}
if(moveBack){
heroWrap.position.x -= Math.cos( hero.rotation.y );
heroWrap.position.z += Math.sin( hero.rotation.y)*1;
if(currentAnimation!='run')
hero.playAnimation( 'run', 6 );
currentAnimation = 'run';
}
if(moveLeft){
hero.rotation.y += Math.PI*2/180;
if(currentAnimation!='run')
hero.playAnimation( 'run', 6 );
currentAnimation = 'run';
}
if(moveRight){
hero.rotation.y -= Math.PI*2/180; //5
if(currentAnimation!='run')
hero.playAnimation( 'run', 6 );
currentAnimation = 'run';
}
hero.position.x = heroWrap.position.x;
hero.position.y = heroWrap.position.y;
hero.position.z = heroWrap.position.z;
camera.position.copy(heroWrap.position).add(new THREE.Vector3(0, 300,0));
var states = [];
for(var key in keys){
states.push(key);
}
if(states.length==0) {
if(currentAnimation!='stand') {
hero.playAnimation( 'stand', 6 );
}
currentAnimation = 'stand';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment