Time for action – get these cubes under control

One type of dedicated jMonkeyEngine class that encapsulates a spatial's behavior is the Control class from the com.jme3.scene.control package. You can create a Control object based on the code mentioned earlier, and add it to an individual cube. This prompts the cube to automatically test its own distance to the camera, and move away when the player looks at it! Seeing is believing:

  1. Create a CubeChaserControl class. Make it extend the AbstractControl class from the com.jme3.scene.control package.
  2. Implement abstract methods of the CubeChaserControl class with the following template:
     @Override protected void controlUpdate(float tpf) { } protected void controlRender(RenderManager rm, ViewPort vp) { } ...

Get jMonkeyEngine 3.0 Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.