throw-on-drop partial examples (working but does not take time into account)

game-multiple-levels
Fabien Benetou 5 months ago
parent 8084105461
commit 0a0ceb8f28
  1. 44
      index.html

@ -115,6 +115,41 @@ function showOnlyThisGame(name){
}
//___________________________________________________________________________________________________________________________________
AFRAME.registerComponent('throw-on-drop', {
init: function(){
let generatorName = this.attrName
let el = this.el
AFRAME.scenes[0].setAttribute("physics", "debug:true")
el.setAttribute("onpicked", 'window.pfp = e.detail.element.getAttribute("position").clone(); e.detail.element.removeAttribute("dynamic-body")')
// could also start an interval instead
el.setAttribute("onreleased", 'toss( e.detail.element )')
}
})
function toss(el, forcedvec){
// time as force multiplier, i.e .1m/s vs .1m/10s
// need to have another variable storing the time when window.pfp changed
//AFRAME.scenes[0].setAttribute("physics", "debug:true")
el.setAttribute("dynamic-body", "")
//el.body.applyImpulse( forcedvec, new CANNON.Vec3().copy(el.getAttribute('position')) )
//el.body.applyForce( forcedvec, new CANNON.Vec3().copy(el.getAttribute('position')) )
// tested via toss( document.querySelector("[throw-on-drop]"), new THREE.Vector3(0,1,-1) )
let pos = new THREE.Vector3().copy( el.getAttribute('position') )
pos.sub( window.pfp )
let vec = new CANNON.Vec3().copy( pos )
console.log("sub", vec ) // probably have to be normalized
//el.body.applyForce( vec, new CANNON.Vec3().copy(el.getAttribute('position')) )
el.body.applyImpulse( vec, new CANNON.Vec3().copy(el.getAttribute('position')) )
// cf https://schteppe.github.io/cannon.js/docs/classes/Body.html#method_applyImpulse
// could try alternatives, e.g applyForce ()
// kind of works... but no notion of power inherited from speed
// also the direction is from start from finish, which is not what others expect
// except if shown, e.g with helper arrow
// could clone and preview movement at interval
// does not move if we pick and release in place
}
/*
physics https://github.com/c-frame/aframe-physics-system and setup docs https://github.com/c-frame/aframe-physics-system/blob/master/CannonDriver.md#installation
should append to head script with src="https://cdn.jsdelivr.net/gh/c-frame/aframe-physics-system@v4.2.2/dist/aframe-physics-system.min.js"
@ -1043,6 +1078,15 @@ S1111
<!-- bug if #box missing, so hiding for now -->
<!-- bug in start-on-press after XR init, as mentioned there -->
<!-- testing on physics to toss/object objects -->
<!-- does not work somehow at that position but -.5! -->
<!--
<a-sphere target throw-on-drop radius=".05" position="0 1.5 -.2" color="orange"></a-sphere>
<a-troika-text throw-on-drop value="movable" target position="0 1.30 -.5" scale="0.1 0.1 0.1"></a-troika-text>
<a-plane position="0 1.1 -.5" rotation="-90 0 0" static-body></a-plane>
-->
</a-scene>
</body>
</script>

Loading…
Cancel
Save