Skip to content

Commit

Permalink
Examples: Added muzzle fire to FPS demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Oct 6, 2018
1 parent ac17e31 commit dcaff13
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
18 changes: 18 additions & 0 deletions examples/entity/shooter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@

mixer = new THREE.AnimationMixer( player.weapon );

buildMuzzleEffect( player.weapon, weaponMesh );
buildAnimations( player.weapon );

} );
Expand Down Expand Up @@ -224,6 +225,23 @@

}

function buildMuzzleEffect( weapon, weaponMesh ) {

const loader = new THREE.TextureLoader();
const texture = loader.load( 'model/muzzle.png' );

const material = new THREE.SpriteMaterial( { map: texture } );
const sprite = new THREE.Sprite( material );

sprite.position.set( 0, 0.13, - 0.4 );
sprite.scale.set( 0.3, 0.3, 0.3 );
sprite.visible = false;

weaponMesh.add( sprite );
weapon.muzzle = sprite;

}

function buildAnimations( weapon ) {

// manually create some keyframes for testing
Expand Down
Binary file added examples/entity/shooter/model/muzzle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion examples/entity/shooter/src/Blaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Blaster extends Weapon {

this.animations = new Map();
this.sounds = new Map();
this.muzzle = null;

}

Expand Down Expand Up @@ -90,7 +91,18 @@ class Blaster extends Weapon {
animation.stop();
animation.play();

//
// muzzle

this.muzzle.visible = true;
this.muzzle.material.rotation = Math.random() * Math.PI;

setTimeout( () => {

this.muzzle.visible = false;

}, 100 );

// adjust ammo

this.roundsLeft --;

Expand Down
2 changes: 1 addition & 1 deletion examples/entity/shooter/src/FirstPersonControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FirstPersonControls extends EventDispatcher {

this.lookingSpeed = 1;
this.brakingPower = 10;
this.headMovement = 1;
this.headMovement = 0.75;

this.input = {
forward: false,
Expand Down
2 changes: 1 addition & 1 deletion examples/entity/shooter/src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Player extends MovingEntity {

//

this.maxSpeed = 80;
this.maxSpeed = 100;
this.updateOrientation = false;

}
Expand Down

0 comments on commit dcaff13

Please sign in to comment.