Time for action – chase all the cubes!

The other cubes are mightily impressed by your new-found cube chasing skills. Can you change the code sample so that you can pick which cube you want to chase, simply by looking at it? Use the ray casting method that you learned in the earlier target picking examples!

  1. Since you will detect cubes with the help of ray casting, create a class field for the ray object.
    private Ray ray = new Ray();
  2. Completely remove the code pertaining to scaredCube—a real cube chaser doesn't need an extra class field to pick a cube.
  3. Put the following code in the simpleUpdate() method loop to keep the ray up-to-date. Use the ray.setOrigin(cam.getLocation()) method and the ray.setDirection(cam.getDirection()) method to aim the ray ...

Get jMonkeyEngine 3.0 Beginner's Guide 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.