Build a Raft for Racing

A donut shape will work very nicely as a river raft. Add the addRaft call to the code outline at the top:

 
addSunlight(scene);
 
var​ scoreboard = addScoreboard();
 
var​ river = addRiver(scene);
 
var​ raft = addRaft(scene);

Now, after the last of the river code, which should be addLid, we start addRaft like this:

 
function​ addRaft(scene) {
 
var​ mesh = ​new​ Physijs.ConvexMesh(
 
new​ THREE.TorusGeometry(2, 0.5, 8, 20),
 
Physijs.createMaterial(
 
new​ THREE.MeshPhongMaterial({
 
emissive: 0xcc2222,
 
specular: 0xeeeeee
 
}),
 
0.1,
 
0.01
 
)
 
);
 
mesh.rotation.x = -Math.PI/2;
 
mesh.castShadow = true;
 
 
scene.add(mesh);
 
mesh.setAngularFactor(​new​ THREE.Vector3(0, 0, 0));
 
 
var​ rudder = ​new​ THREE.Mesh( ...

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.