Game Development Community

Adding Sound?

by Valerie Butler · in Torque Game Engine · 07/01/2009 (12:02 pm) · 6 replies

Hi guys, sorry if my question seems basic, but how do I go about adding a simple background sound to my game and also the sound of footsteps when the character moves?

#1
07/01/2009 (12:37 pm)
You'll need to set up Audio Description/Profile datablocks to get started. There used to be several good tutorials for adding various types of sounds on TDN... this basic type of documentation has gotten worse over the past year :( -- but there is still this one for level music, if that's what you're looking for.

Another alternative is to use AudioEmitters, which are placed through the Mission Editor, and will give localized 3d sound.

Player footstep sounds have a dependency on footstep triggers in the animations (dsq's) of the model that fire off and are used in the c++ code, the animation docs for Studio Max I believe cover this. This allows the player model to play a sound when it takes a step (soft/hard/metal/snow). You can see how these sounds are determined in the various propertyMap.cs files for Interiors and Terrains, and then used in player.cc and interiorCollision.cc (could be a few other places too).
#2
07/02/2009 (5:55 am)
Thanks Michael, worked with that tutorial and got the sound playing! It had a crackle in it and I managed to fix that by changing the openAL32.dll to the older version (0.9.5.1) for some reason!

On the footsteps, I do not have a character or animation it is simply a first person game! I just need to play a sound on loop while the player is moving forward!

In the moveforward function I tried

function moveforward(%val)
{
$musicHandle = alxPlay(Footstep);
$mvForwardAction = %val * $movementSpeed;
}

This sound is unlooped and only plays once when the button is pressed but does not continue looping until the button is unpressed! Basically I just want a sound to play on loop while a button is pressed and then to stop when it is unpressed! How might I do this?

Thank you for your help! :-)
#3
07/02/2009 (6:41 am)
Define your Footstep sound as looping, and stop it when moveforward is called with %val = 0.

Nicolas Buquet
www.buquet-net.com/cv/
#4
07/02/2009 (7:05 am)
Thanks Nicolas.. I understand what your saying but not sure how to implement it... Like this? I tried this but I think my implementation is wrong.. What changes would you make? Thanks again!

function moveforward(%val)
{
if(%val)
{
$musicHandle = alxPlay(Footstep);
$mvForwardAction = %val * $movementSpeed;
}
else if (%val=0)
{
alxStop($musicHandle);
}
}
#5
07/02/2009 (8:04 am)
Thanks guys... Got all my sound sorted out! :)
#6
07/02/2009 (9:32 am)
Glad you got it working :)

Here's my take on "scripted" footsteps that uses client to server CMDs for networkability and a schedule instead of a "looping" sound... although there are several ways of handling this.
// DATABLOCK
datablock AudioProfile(FootStep1)
{
   fileName = "~/data/sound/FootStep1.wav";
   description = AudioClosest3d;
   preload = true;
};

// SERVER-SIDE SCRIPTS
function serverCmdStartFootsteps(%client)
{
   %client.player.schedule(200, playFootstep);
   %client.player.footstepson = true;
}

function serverCmdStopFootsteps(%client)
{
   %client.player.footstepson = false;
}

function Player::playFootstep(%this)
{
   if(%this.footstepson)
   {
      serverPlay3D(FootStep1, %this.getTransform());
      %this.schedule(500, playFootstep);
   }
}

// CLIENT-SIDE SCRIPTS
function moveForward(%val)
{
   $mvForwardAction = %val;
   if (%val)
      commandToServer('startFootsteps');
   else
      commandToServer('stopFootsteps');
}

moveMap.bind(keyboard, w, moveForward);