Game Development Reference
In-Depth Information
How to do it...
We will begin by setting up some things that are not strictly needed for the rocket engine
but will aid the testing. Perform the following steps to build a rocket engine:
1. First of all we add a floor mesh. For this, we create a new
Node
class called
ground
.
2. To do this, we add
RigidBodyControl
with
PlaneCollisionShape
. The
plane should face upwards like floors normally do, as follows:
RigidBodyControl floorControl = new
RigidBodyControl(new PlaneCollisionShape(new Plane(new
Vector3f(0, 1, 0), 0)), 0);
ground.addControl(floorControl);
floorControl.setPhysicsLocation(new Vector3f(0f, -10,
0f));
3. We then attach them both to
rootNode
of the application and
physicsSpace
of
bulletAppState
.
4. Finally, we need to add a key to control the booster. For this, we implement an
AnalogListener
interface in our application.
5. Then, add the application to
inputManager
along with a mapping object called
boost that is bound to the Space bar:
inputManager.addListener(this, "boost");
inputManager.addMapping("boost", new
KeyTrigger(KeyInput.KEY_SPACE));
6. Most of this recipe will be implemented in a class that extends
SimpleApplic-
ation
.
7. We begin by defining a
Node
class called
spaceShip
that will be our space-
ship's representation.
8. We then create a
RigidBodyControl
instance with
BoxCollisionShape
and add it to the
spaceShip
node as follows:
RigidBodyControl control = new RigidBodyControl(new
BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
spaceShip.addControl(control);