Building Draggable Ramps

It is a long way up to the top of the screen. game players are going to need at least two ramps to reach the top. To build two ramps that behave the same way but are separate, we’ll need to construct some JavaScript objects as we did in Chapter 17, Project: Learning about JavaScript Objects.

We start by defining our ramp constructor. Since it constructs objects, we capitalize the name of the constructor function as Ramp. In the constructor, we define one property, the ramp mesh, and call three methods:

 
function​ Ramp(x, y) {
 
this.mesh = ​new​ Physijs.ConvexMesh(
 
new​ THREE.CylinderGeometry(5, height * 0.05, height * 0.25),
 
Physijs.createMaterial(
 
new​ THREE.MeshBasicMaterial({color:0x0000cc}), 0.2, 1.0 ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.