Skip to content

Instantly share code, notes, and snippets.

@sasha240100
Last active September 26, 2017 16:00
Show Gist options
  • Save sasha240100/26152d70eb03dc398a476b15dd91af52 to your computer and use it in GitHub Desktop.
Save sasha240100/26152d70eb03dc398a476b15dd91af52 to your computer and use it in GitHub Desktop.
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