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.
We will start by defining a class that all objects emitting sounds will use. This will require the following steps to be performed:
We create a class called
SoundEmitterControl
, extendingAbstractControl
.It needs three fields, a
Vector3f
calledlastPosition
, a float fornoiseEmitted
, and another float calledmaxSpeed
.In the
controlUpdate
method, we sample the...