Terrain sounds.. how to?
by arteria3d · in Torque Game Engine · 12/18/2004 (2:59 pm) · 31 replies
Hi,
I have looked through quite a few forumn threads and done loads of experimenting as to how to alter the sounds, as the player walks on different textures on the terrains.
First of all - can anyone help how to do it.. and secondly does this system require a complete texture on its own on the terraiin - and what happens between blended parts of two textures.
Thanks
Steve
I have looked through quite a few forumn threads and done loads of experimenting as to how to alter the sounds, as the player walks on different textures on the terrains.
First of all - can anyone help how to do it.. and secondly does this system require a complete texture on its own on the terraiin - and what happens between blended parts of two textures.
Thanks
Steve
About the author
Owner of uk based Ltd company ArteriaMediaLtd. with a trading name of Arteria3d Website;arteria3d.com
#2
12/18/2004 (4:06 pm)
Hey Stephen hy there... Thanks for your help again.. I am a lot more happy with performance now too! i have added lots more to my level - and now gonna conentrate on some solid area of the game. Swim code... is next....
#3
You set what sound in the materialproperty map .
And the sounds come form the player.cs the footsounds.
12/18/2004 (4:24 pm)
Footstep sounds trigger after what material you have under your feet.You set what sound in the materialproperty map .
And the sounds come form the player.cs the footsounds.
#4
// create the audio for the step
//
datablock audioprofile(footstep)
{
filename="your path your file";
description=audioclosest3d;
preload=true;
}
function servercmdstartfootsteps(%client)
{
%client.player.schedule(200,playerfootstep);
%client.player.footstepson=true;
}
function severcmdstopfootsteps(%client)
%client.player.footstepson=false;
}
function player::playfootstep(%this)
}
if(%this.footstepson)
{serverplay3d(footstep,%this.gettransform());
this.schedule(500,playfootsep;)
}
}
//And this in sndprofiles.cs
Datablock audiodescription(audioclosest3d)
{
volume=1.0;
islooping=false;
is3d=true;
referencedistance=5.0;
maxdistance=30.0;
type=$simaudiotype;
;
// to know when to play the sound change put this code in misc\presetkeys.cs
function goahead(%val)
{
$mvforwardaction=%val;
if(%val)
commandtoserver('startfootseps');
else
commandtoserver('stopfootseps');
}
/instead of
function goahead(%val)
{
$mvforwardaction=%val;
}
that should do it.
Of course, I totaly bit that out of ken Finneys 3d game programming all in one
Wich you should get if you don't have it already. It really is a great book and all the scripting is in Torque
12/18/2004 (4:25 pm)
Put this in player.cs right after Humanmaleavatar::onDisabled// create the audio for the step
//
datablock audioprofile(footstep)
{
filename="your path your file";
description=audioclosest3d;
preload=true;
}
function servercmdstartfootsteps(%client)
{
%client.player.schedule(200,playerfootstep);
%client.player.footstepson=true;
}
function severcmdstopfootsteps(%client)
%client.player.footstepson=false;
}
function player::playfootstep(%this)
}
if(%this.footstepson)
{serverplay3d(footstep,%this.gettransform());
this.schedule(500,playfootsep;)
}
}
//And this in sndprofiles.cs
Datablock audiodescription(audioclosest3d)
{
volume=1.0;
islooping=false;
is3d=true;
referencedistance=5.0;
maxdistance=30.0;
type=$simaudiotype;
;
// to know when to play the sound change put this code in misc\presetkeys.cs
function goahead(%val)
{
$mvforwardaction=%val;
if(%val)
commandtoserver('startfootseps');
else
commandtoserver('stopfootseps');
}
/instead of
function goahead(%val)
{
$mvforwardaction=%val;
}
that should do it.
Of course, I totaly bit that out of ken Finneys 3d game programming all in one
Wich you should get if you don't have it already. It really is a great book and all the scripting is in Torque
#5
This function about footstep sounds and differnt dust colors are already in the engine !
you dont need any servercommands or something.
12/18/2004 (4:32 pm)
@charlieThis function about footstep sounds and differnt dust colors are already in the engine !
you dont need any servercommands or something.
#6
12/18/2004 (4:41 pm)
Well i guess I just got some practice typing then.
#7
I have tried and tried in what seems like a simple process. - defining sounds for terrain texture 0,1,2,3 etc etc - but it doesnt work....
12/18/2004 (4:46 pm)
If its already in the engine why doesnt it work!I have tried and tried in what seems like a simple process. - defining sounds for terrain texture 0,1,2,3 etc etc - but it doesnt work....
#9
You will need to develop that yourself, although as I said, take a look at how they change the sound the player emits when they enter water, and you'll see the technique for a specific change.
Now, figure out how to know what terrain type you are on (I don't think this is trival off the top of my head in script, it may take some coding, but I haven't looked into it at all), and then swap the sound type based on the terrain type you're on, and you'll be well on your way.
FYI: The code listed above doesn't change the sound emitted based on terrain type either. It simply turns on/off the footstep sounds itself, and makes sure it's being emitted from the player's position.
12/18/2004 (5:05 pm)
@Stevie--as I said above, TGE does not change the sound of the footsteps based on terrain--it doesn't even change the type of footpuff (footprint dust) emitter based on Terrain type.You will need to develop that yourself, although as I said, take a look at how they change the sound the player emits when they enter water, and you'll see the technique for a specific change.
Now, figure out how to know what terrain type you are on (I don't think this is trival off the top of my head in script, it may take some coding, but I haven't looked into it at all), and then swap the sound type based on the terrain type you're on, and you'll be well on your way.
FYI: The code listed above doesn't change the sound emitted based on terrain type either. It simply turns on/off the footstep sounds itself, and makes sure it's being emitted from the player's position.
#10
Torque changes both footpuffs and sound and it working real good !!
12/18/2004 (5:39 pm)
@StephenTorque changes both footpuffs and sound and it working real good !!
#11
Stevie
12/18/2004 (5:43 pm)
Billy - when i did the changes, torque just stayed with one sound continuously looping?? Straight as i started to move, the sound would start - loop continuous. When i stopped it would still stay on for a while?Stevie
#12
As well as footpuffs (NOT footprints)--the little bit of dust that kicks up as you run. You are getting different images when you run on rock, as opposed to grass or dirt?
12/18/2004 (5:45 pm)
@Billy--you are saying that you get different sounds depending on the type of terrain you are on? For example, footsteps on rock are different from footsteps on grass, or mud, or dirt, or marsh?As well as footpuffs (NOT footprints)--the little bit of dust that kicks up as you run. You are getting different images when you run on rock, as opposed to grass or dirt?
#13
I send up a test file so you can see !
12/18/2004 (5:52 pm)
Yep puffs change color and so does the sounds thats right !I send up a test file so you can see !
#14
This is stock TGE you are talking about, right?
12/18/2004 (5:59 pm)
Ok, I stand corrected--have never seen that happen myself. I specifically remember seeing dirt footpuffs on rock, and I -know- I don't have a bunch of different footstep .ogg files for my orc!This is stock TGE you are talking about, right?
#15
Anyway, in that demo, when the dude runs up a hill and it starts snowing the foot puffs change to white and you get a more crunchy snow sound for foot steps.
It really shouldnt be harder then doing some check on current terrain and changing the sound when the terrain has changed.
Changing sounds when in buildings and bridges and such would be about the same.
I ran across something about checking player position on terrain. When I find it again I'll post it
12/18/2004 (6:00 pm)
Stephen, I had a demo that I came across somewhere but I don't know where it went after I reformated.Anyway, in that demo, when the dude runs up a hill and it starts snowing the foot puffs change to white and you get a more crunchy snow sound for foot steps.
It really shouldnt be harder then doing some check on current terrain and changing the sound when the terrain has changed.
Changing sounds when in buildings and bridges and such would be about the same.
I ran across something about checking player position on terrain. When I find it again I'll post it
#16
I just stepped through the code, and yes, it certainly does support different sound profiles based on terrain. The reason that in the demo it isn't obvious is because most of the sound profiles are initialized to1 of the 3 sound files given in the demo, so while it's set up to play different sounds for different types of terrain, you have to supply different sound files for them.
Appropriate areas of the code to look at:
player.cs, all of the audio profile stuff.
player.cc, good place to start is
void Player::playFootstepSound(bool triggeredLeft, S32 sound)
Sorry for confusing the issue all.
12/18/2004 (6:11 pm)
Well, you learn something every day!I just stepped through the code, and yes, it certainly does support different sound profiles based on terrain. The reason that in the demo it isn't obvious is because most of the sound profiles are initialized to1 of the 3 sound files given in the demo, so while it's set up to play different sounds for different types of terrain, you have to supply different sound files for them.
Appropriate areas of the code to look at:
player.cs, all of the audio profile stuff.
player.cc, good place to start is
void Player::playFootstepSound(bool triggeredLeft, S32 sound)
Sorry for confusing the issue all.
#18
Finally, in your terrain/grassland (or /highland) there is a file called propertyMap.cs. This contains the mapping between the terrain (texture) type, and which sound gets played.
In the stock release, all of the ones I looked at were set to "sound: 0", so I'm not quite sure what to set here to map specific sounds, but my guess would be it's the order in which the profiles are added in. You would need to experiment on that.
12/18/2004 (6:21 pm)
Start by adding in some new .ogg files to your /sound directory, and then changing some of the audio profiles in player.cs to play the appropriate ones.Finally, in your terrain/grassland (or /highland) there is a file called propertyMap.cs. This contains the mapping between the terrain (texture) type, and which sound gets played.
In the stock release, all of the ones I looked at were set to "sound: 0", so I'm not quite sure what to set here to map specific sounds, but my guess would be it's the order in which the profiles are added in. You would need to experiment on that.
#19
Dont know why grr ..
I send you both a test exe with mission by mail !
Edit: cant send you a mail Stevie not working !
12/18/2004 (6:26 pm)
I tried to send up an example file but my site looks to be down.Dont know why grr ..
I send you both a test exe with mission by mail !
Edit: cant send you a mail Stevie not working !
#20
in player.cc
change line 2099
Change the terrain propertymap.cs to something like this
hope it works now !
12/18/2004 (7:38 pm)
Ok guys i assumed they fixed this long time ago , they fixed part of it only :)in player.cc
change line 2099
S32 mapIndex = tBlock->mMPMIndex[0];to
S32 mapIndex = tBlock->getTerrainMapIndex(rInfo.point);
Change the terrain propertymap.cs to something like this
addMaterialMapping( "sand" , "sound: 0" , "color: 0.96 0.36 0.26 0.4 0.0" ); addMaterialMapping( "grass" , "sound: 1" , "color: 0.46 0.96 0.26 0.4 0.0" ); addMaterialMapping( "patchy" , "sound: 2" , "color: 0.46 0.36 0.96 0.4 0.0" );
hope it works now !
Torque 3D Owner Stephen Zepp
Now, one exception here is water sounds, and between the two I think you could figure out a good technique to swap different sound files in/out.
That being said, it should be easily expandable to check the underlying terrain type (and you bring up a good point about blended terrain, you would have to determine what your design would deem appropriate for the right sound in this case), and then swap out the sound being played on the client based on that check.
I think the player sounds are all defined in player.cs, so you may want to start there. Also, search in scripts for "Play" (search in all files is VERY nice here), and start opening up files that look like they have similar script commands.