But, more importantly, when the avatar does cartwheels, the camera doesn’t
move. The avatar is cartwheeling, but the marker doesn’t spin. Since the
marker is not spinning, the camera doesn’t spin either.
In 3D programming, this marker is just a marker. It should be invisible. So
we don’t want to use meshes or geometries for this. Instead we use Object3D.
Let’s add the following code before the avatar-generated code, just after START
CODING ON THE NEXT LINE.
varmarker =newTHREE.Object3D();
scene.add(marker);
Now we change the avatar so that it is added to the marker instead of adding
it to the scene:
varavatar =newTHREE.Mesh(body, cover);
marker.add(avatar);
We also need to change how the camera is added. Instead of adding the
camera to the avatar, we add it to the marker.
marker.add(camera);
The last thing we need to change is the keyboard event listener. Instead of
changing the position of the avatar, we have to change the position of the
marker.
Chapter 4. Project: Moving Avatars • 46
Prepared exclusively for Michael Powell report erratum • discuss