From 87407c255205abacc63255c36940658b36f271b1 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Sun, 29 Oct 2023 18:12:40 +0100 Subject: [PATCH] cone change as core feedback mecanics --- index.html | 26 +++++++++++++------------- jxr.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index e6d02b1..0e2f3ef 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@ - + - - - - - - - - - - - + + + + + + + + + + + + diff --git a/jxr.js b/jxr.js index 32c5809..a5b4e21 100644 --- a/jxr.js +++ b/jxr.js @@ -3513,13 +3513,12 @@ AFRAME.registerComponent('unpackable', { }) AFRAME.registerComponent('trail', { - init: function () { let player = document.getElementById('player') // assuming single player, non networked let previousPos setInterval( _ => { let pos = player.getAttribute('position').clone() - pos.y = 1 + pos.y = 0 // compare current pos with previous set ones and if below distance threshold, lose points let hits = Array.from(document.querySelectorAll('.trail')) .filter( e => e.getAttribute("visible") == true) @@ -3532,16 +3531,16 @@ AFRAME.registerComponent('trail', { } if (previousPos && previousPos.distanceTo(pos) < 0.1) return // threshold to avoid cluttering let el = document.createElement('a-cylinder') - el.setAttribute('scale', '.2 2 .2') + el.setAttribute('scale', '.2 .2 .2') el.setAttribute('position', AFRAME.utils.coordinates.stringify( pos ) ) el.setAttribute('color', 'green') - el.setAttribute('opacity', '0.3') + el.setAttribute('opacity', '0.03') el.setAttribute('segments-radial', '6') el.setAttribute('segments-height', '2') el.className += 'trail' this.el.appendChild(el) previousPos = player.getAttribute('position').clone() - previousPos.y = 1 + previousPos.y = 0 }, 50) }, remove: function () { @@ -3549,6 +3548,32 @@ AFRAME.registerComponent('trail', { } }) +let changeovercheck +AFRAME.registerComponent('changeover', { + schema: { color : {type: 'string'} }, + init: function () { + // (this.el, this.data.content) + if (changeovercheck) return + let player = document.getElementById('player') // assuming single player, non networked + console.log('adding timer') + changeovercheck = setInterval( _ => { + let pos = player.getAttribute('position').clone() + pos.y = 0.1 // hard coded but should be from component element + let hits = Array.from(document.querySelectorAll('[changeover]')) + .filter( e => e.getAttribute("visible") == true) + .map( t => { return { el: t, dist : pos.distanceTo(t.getAttribute("position") ) } }) + .filter( t => t.dist < 0.02 ) + .sort( (a,b) => a.dist > b.dist) + console.log(hits.length) + if (hits.length>0) { + setFeedbackHUD('touching cone') + console.log('touching cone') + hits[hits.length-1].el.setAttribute('color', 'red') + } + }, 50) + } +}) + // used for testing, now that jxr.js is outside of index.html, could consider putting this back in index.html instead to keep behavior one would expect from a library // does indeed create problems, namely other pages relying on it do get this testing behavior AFRAME.registerComponent('startfunctions', {