3D Game Programming

(C. Jardin) #1

With that, we have a cool-looking river winding its way through the land:


Finally, we define the lid function as the following:


functionaddLid(ground, size) {
varlid =newPhysijs.ConvexMesh(
newTHREE.CubeGeometry(size, size, 1),
newTHREE.MeshBasicMaterial({visible:false})
);
ground.add(lid);
}

This invisible lid is an easy addition to keep our raft from jumping the river
banks. Speaking of the raft, we’ll add that next.

20.4 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);
varscoreboard = addScoreboard();
varriver = addRiver(scene);
varraft = addRaft(scene);

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

functionaddRaft(scene) {
varmesh =newPhysijs.ConvexMesh(
newTHREE.TorusGeometry(2, 0.5, 8, 20),
Physijs.createMaterial(
newTHREE.MeshPhongMaterial({
emissive: 0xcc2222,
specular: 0xeeeeee

report erratum • discuss

Build a Raft for Racing • 195


Prepared exclusively for Michael Powell

Free download pdf