repo: janusweb action: commit revision: path_from: revision_from: b3529eafd342b5f7dcfea642f30096078bbf7190: path_to: revision_to:
commit b3529eafd342b5f7dcfea642f30096078bbf7190 Author: James BaicoianuDate: Tue Dec 10 14:46:34 2019 -0800 Added player.lookAt() diff --git a/scripts/janusplayer.js b/scripts/janusplayer.js
--- 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-----