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

Sensing – hearing


The hearing we'll implement is one of the more basic models you can have. It's not as direct as vision, and requires a different approach. We'll assume that hearing is defined by hearingRange, and that the hearing ability has a linear fall off to that radius. We'll also assume that the sound emits something (in this case, footsteps), the volume of which is relative to the object's velocity. This would make sense in a stealth game, where sneaking should emit less sound than running. Sound is not blocked by obstacles or modified in any other way, apart from the distance between the target and the listener.

How to do it...

We will start by defining a class that all objects emitting sounds will use. This will require the following steps to be performed:

  1. We create a class called SoundEmitterControl, extending AbstractControl.

  2. It needs three fields, a Vector3f called lastPosition, a float for noiseEmitted, and another float called maxSpeed.

  3. In the controlUpdate method, we sample the...