Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Ballistic projectiles and arrows


Applying physics to arrows can greatly improve the appearance and gameplay of a medieval or fantasy game. Setting up arrows that are affected by gravity is fairly simple; this recipe, however, will also set the arrows up in a way that they always face the direction they're traveling in, making them more realistic. The following figure shows one of the arrows in flight:

Getting ready

For this recipe, we need to make sure that we see the debug shapes of physics. To do this, we need to call the bulletAppState.setDebugEnabled(true); statement.

How to do it...

In this recipe, we'll create three classes. Let's begin by looking at the Arrow class, which contains most of the new functionalities. This will be done in the following eight steps:

  1. We create a new class called Arrow, extending Node.

  2. Its constructor takes two Vector3f variables as parameters. One of these is for the starting location of the arrow and one for the initial velocity, as shown in the following line...