Learning Three.js 2: Catch the Sphere
The second thing that I have made in my endeavours to learn three.js is a simple catch the sphere game. Every time you get close to the orange sphere, it will move it to another random place in the room, add one to your score, and play a sound.
I cheated a little bit on the collision detection... I really ought to look into writing a simple 3D collision detection library that uses boxes and spheres.
The collision detection for the sphere is really done in 2D - I check only on the x
and z
axes to see if you are within a certain distance of the sphere since your y
position doesn't change. For the bounding box, I simply check to make sure that your x
and z
co-ordinates aren't too big or too small.
You can find it here: two