From 5c0762d59b054e16b2f474f56f0e5eac7534c5ea Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 10 Apr 2023 22:52:33 +0200 Subject: [PATCH] basic projectile example --- index.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.html b/index.html index 1527232..e389797 100644 --- a/index.html +++ b/index.html @@ -3053,6 +3053,26 @@ AFRAME.registerComponent('gate-through', { } }); +function shoot(){ + s = document.createElement("a-sphere"); + s.setAttribute("radius", .01); + AFRAME.scenes[0].appendChild(s); + v = new THREE.Vector3(); + p = new THREE.Vector3(); + t = new THREE.Vector3(); + cam = AFRAME.scenes[0].object3D.getObjectByProperty("type", "PerspectiveCamera"); + cam.getWorldDirection(v); + cam.getWorldPosition(p); + r = new THREE.Ray( p, v ); + d=0; + shot = setInterval( _ => { + d+=.1; + r.at(d, t); + s.setAttribute("position", AFRAME.utils.coordinates.stringify( t )); + if (d>100) clearInterval(shot) + }, 10) +} + // used for testing AFRAME.registerComponent('startfunctions', { init: function () {