I am currently working on creating a 3D Breakout game using three.js. Most of the collision detection for the walls is already implemented, but I'm facing difficulties with the collision against the paddle.
Below is my code snippet:
// A 3D breakout game by Samuel Steele
Play();
function Play() {
// Declare scene and camera
var width = window.innerWidth;
var height = window.innerHeight;
var velocityX = -1, velocityZ = -2;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, width / height, .1, 1000);
// Initialize WebGL Context
var renderer = new THREE.WebGLRenderer();
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
// Create light
var light = new THREE.PointLight(0xecf0f1, 1.3, 600);
light.position.set(0, 0, 32);
scene.add(light);
// Create paddle
// More object creation...
// Add objects to the scene
// Position objects...
// Collision and movement logic...
render();
}
document.addEventListener("keydown", onDocumentKeyDown, false);
function onDocumentKeyDown(event) {
// Key press event handling
}
// Render function
<p>You can view a live demo <a href="http://cryptocosm.x10.bz/gms/three.Breakout" rel="nofollow">here</a>, developed using Three.js r62.</p>