javascript - Three js, get the vector3 that pointerlockcontrolsi s facing -


wondering if it's possible way yaw object in pointer lock controls facing , use direction raycaster. i've been toying around code, trying add basic shooter stuff it. i've been trying few things i've found on stack overflow x & y values yaw object pointer controls provides, no luck. here's have far:

setuptarget: function() {   //var vector = new three.vector3(game.mouse.x, game.mouse.y, 0);   var yaw = game.controls.getobject();   var pitch = game.controls.pitchobject;   var vector = new three.vector3(     yaw.position.x * math.cos(pitch.rotation.x),     yaw.position.y * math.sin(yaw.rotation.y),     0   );   var dir = vector.sub(yaw.position).normalize();   this.ray = new three.raycaster(yaw.position.clone(), dir); } 

i know that's wrong aside it's not working. confusing math calculating x & y translation based on rotation, doesnt work target obviously.

add following copy of pointerlockcontrols ( or wait few days next release):

this.getdirection = function() {      // assumes camera not rotated      var direction = new three.vector3( 0, 0, -1 );     var rotation = new three.euler( 0, 0, 0, "yxz" );      return function( v ) {          rotation.set( pitchobject.rotation.x, yawobject.rotation.y, 0 );          v.copy( direction ).applyeuler( rotation );          return v;      }  }(); 

three.js r.59


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -