repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 09b52fad7d684a09679f3c65ae24a4ed48051fbf:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 09b52fad7d684a09679f3c65ae24a4ed48051fbf
Author: James Baicoianu 
Date:   Tue Sep 3 11:23:31 2024 -0700

    Added player.turnTo() and turnhead parameter for player.lookAt()

diff --git a/scripts/janusplayer.js b/scripts/janusplayer.js
index de69a034ef9187f41947fc74d6735af574c0d2cd..
index ..848d94f776acd6e0b2323d4ad0e868e4f540285c 100644
--- a/scripts/janusplayer.js
+++ b/scripts/janusplayer.js
@@ -1106,7 +1106,30 @@ document.body.dispatchEvent(click);
     this.dispatchEvent = function(event, target) {
       let firedev = elation.events.fire(event);
     }
-    this.lookAt = function(other, up) {
+    this.lookAt = function(other, up, turnhead) {
+      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();
+        if (turnhead) {
+          this.head.properties.orientation.setFromEuler(new THREE.Euler(-Math.asin(dir.y), Math.atan2(dir.x, dir.z), 0, 'XYZ'));
+        } else {
+          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();
+      }
+    }
+    this.turnTo = function(other, up) {
       if (!up) up = new THREE.Vector3(0,1,0);
       var otherpos = false;
       if (other.properties && other.properties.position) {

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