basic projectile example

game-mechanics
Fabien Benetou 2 years ago
parent 5292263692
commit 5c0762d59b
  1. 20
      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 () {

Loading…
Cancel
Save