repo: janusweb
action: commit
revision: 
path_from: 
revision_from: b3529eafd342b5f7dcfea642f30096078bbf7190:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit b3529eafd342b5f7dcfea642f30096078bbf7190
Author: James Baicoianu 
Date:   Tue Dec 10 14:46:34 2019 -0800

    Added player.lookAt()

diff --git a/scripts/janusplayer.js b/scripts/janusplayer.js
index ae7bf95f9b269ca25af3ce6633d8adab60f40d60..
index ..60069e8cbaacdc7baebaa96c3acef0b1568bf38c 100644
--- a/scripts/janusplayer.js
+++ b/scripts/janusplayer.js
@@ -867,5 +867,24 @@ elation.require(['engine.things.player', 'janusweb.external.JanusVOIP', 'ui.butt
     this.dispatchEvent = function(event, target) {
       let firedev = elation.events.fire(event);
     }
+    this.lookAt = function(other, up) {
+      if (!up) up = new THREE.Vector3(0,1,0);
+      var otherpos = false;
+      if (other.properties && other.properties.position) {
+        otherpos = other.localToWorld(new THREE.Vector3());
+      } else if (other instanceof THREE.Vector3) {
+        otherpos = other.clone();
+      }
+      var thispos = this.localToWorld(new THREE.Vector3());
+
+      if (otherpos) {
+        var dir = thispos.clone().sub(otherpos).normalize();
+        this.properties.orientation.setFromEuler(new THREE.Euler(0, Math.atan2(dir.x, dir.z), 0));
+        this.head.properties.orientation.setFromEuler(new THREE.Euler(-Math.asin(dir.y), 0, 0));
+        this.refresh();
+        room.refresh();
+        this.engine.systems.render.setdirty();
+      }
+    }
   }, elation.engine.things.player);
 });

-----END OF PAGE-----