Last active
September 26, 2017 16:00
-
-
Save sasha240100/26152d70eb03dc398a476b15dd91af52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const loop_raycaster = (APP) => { | |
const cameraNative = APP.camera.getNative(); | |
const raycaster = APP.raycaster; | |
const ray = APP.raycaster.ray; | |
const plane = APP.planeForRaycasting; | |
return new WHS.Loop(() => { | |
raycaster.setFromCamera( | |
new THREE.Vector2( | |
(APP.cursor.x / window.innerWidth) * 2 - 1, | |
-(APP.cursor.y / window.innerHeight) * 2 + 1 | |
), | |
cameraNative | |
); | |
const bPos = APP.ball.position; | |
const raycastPoint = ray.at(ray.distanceToPlane(plane)); | |
if (!APP.levelMenuTriggered && APP.animComplete && bPos.z > 60) APP.triggerLevelMenu(); | |
if (APP.levelMenuTriggered && APP.animComplete && bPos.z < 170) APP.goBackToLevel(); | |
APP.ball.setLinearVelocity(raycastPoint.sub(bPos).multiplyScalar(2)); | |
}); | |
} | |
// LOOP: keep_ball |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment