JovRiver / CS-4900-Project

Javascript Web based game.
0 stars 1 forks source link

Enemy Aiming #105

Open mhh916 opened 4 years ago

mhh916 commented 4 years ago

Create a direction ray that offsets by a random value to not 100% accurately hit the player. Then have a raycaster follow that direction to see if it lines up with the player mesh and if it does trigger a hit. Play the playerHit sound effect and subtract life from the player. Life is a global variable and once life hits 0 game over.

mhh916 commented 4 years ago

var direction = new THREE.Vector3(); // create once an reuse it dir.subVectors( v2, v1 ).normalize();

Then get the dir and add offset dir.x += random(); // very small number dir.y += random(); // very small number dir.z += random(); // very small number

Then let position = new THREE.Vector3(); enemy.getWorldPosition(position); let raycaster= new THREE.Raycaster(); // create once and reuse raycaster.set( position, direction ); raycaster.near = 1; raycaster.far = 50; let intersects = movementCaster.intersectObject( player);

Then if it intersects player life - 1; check if 0 then game over