Game Development Reference
In-Depth Information
There's moreā€¦
Let's create a test case world we can use for both this and many of the following recipes.
First we need a world with physics:
BulletAppState bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
We will need some kind of object to stand on. The PhysicsTestHelper class has a
few example worlds we can use.
We load up good old Jaime. Again, we use the BetterCharacterControl class since
it offloads a lot of code for us. Since the Bullet physics world is different from the ordinary
scenegraph, Jaime is added to physicsSpace as well as to the rootNode , as shown in
the following code:
bulletAppState.getPhysicsSpace().add(jaime);
rootNode.attachChild(jaime);
We also need to add our newly created AI control using the following code:
jaime.addControl(new AIControl());
There's one more thing we need to do for this to work. The AI needs to track something.
The easiest way we can get a moving target is to add a CameraNode class and supply
cam from the application, as shown in the following code:
CameraNode camNode = new CameraNode("CamNode", cam);
camNode.setControlDir(CameraControl.ControlDirection.CameraToSpatial);
rootNode.attachChild(camNode);
We set camNode to be the target, as shown in the following code:
jaime.getControl(AIControl.class).setState(AIControl.State.Follow);
jaime.getControl(AIControl.class).setTarget(camNode);
If we're familiar with cameras in OpenGL, we know they don't really have a physical exist-
ence. A CameraNode class in jMonkeyEngine gives us that. It tracks the camera's posi-
Search WWH ::




Custom Search