Building a Random, Unreachable Goal

Let’s make the goal a green donut. Don’t forget to wrap the normal 3D mesh inside the physics mesh for easy collisions.

 
var​ goal = ​new​ Physijs.ConvexMesh(
 
new​ THREE.TorusGeometry(100, 25, 20, 30),
 
Physijs.createMaterial(
 
new​ THREE.MeshBasicMaterial({color:0x00bb00})
 
),
 
0
 
);
 
goal.isGoal = true;

The very last line is how we tell the avatar that this is the goal. We created the avatar’s collision detection so that it checked for this isGoal property. Nothing else in our game has this property set, which lets us be certain that the avatar really has reached the goal.

Next we do something a little different: we place the goal at one of three random locations. In JavaScript, a random number ...

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.