repo: janusweb action: commit revision: path_from: revision_from: 09b52fad7d684a09679f3c65ae24a4ed48051fbf: path_to: revision_to:
commit 09b52fad7d684a09679f3c65ae24a4ed48051fbf Author: James BaicoianuDate: 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
--- 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-----