Different sounds/explosions for different surfaces.
by Chris Byars · in Torque Game Engine · 02/11/2006 (6:43 pm) · 5 replies
..how can I set different sounds and explosions depending on what surface a projectile hits?
For example, if I shoot a bullet at a metal wall, sparks will fly, and a tink will be heard; if I shoot a bullet at the dirt, a poof of smoke will be seen, and a thump will be heard.
TIA
(Thanks in advance for the non social group)
For example, if I shoot a bullet at a metal wall, sparks will fly, and a tink will be heard; if I shoot a bullet at the dirt, a poof of smoke will be seen, and a thump will be heard.
TIA
(Thanks in advance for the non social group)
#2
in the code below rInfo is the castray used in the projectile processtick call. rinfo carried the material number
which is then converted to type and flags (I have my reasons for the slight convolution)
for interior objects :
for terrain :
The following code (placed around line 452 in interiorcollision.cc (TGE 1.4) adds the material number mapping to the rinfo castray for interiors (not needed for terrain):-
To make this more useful (and as I havent written a castray solution for shapes) I added 2 additional member fields to simbase called materialtype and materialflags. These can then be used per object (with the usual net code calls) for material properties or you can use mapping per texture too.
For the effects,I added an array of particle effects to projectile (much like the existing decal code) and made each effect material type number the index of the array for lazy calling.
Material flags I use for effects such as shoot through (decal both sides and dont stop bullet), particle effect but no decal etc etc.
I wont be giving a resource at this time as it is still a work in progress.
02/12/2006 (1:28 pm)
As a starter for 10 :)in the code below rInfo is the castray used in the projectile processtick call. rinfo carried the material number
which is then converted to type and flags (I have my reasons for the slight convolution)
for interior objects :
//material mapping code
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pMatEnt = pMatMap->getMapEntryFromIndex(rInfo.material);
if (pMatEnt)
{
mMaterialHitType = pMatEnt->matType;
mMaterialHitFlags = pMatEnt->matFlags;
}for terrain :
TerrainBlock* tBlock = static_cast<TerrainBlock*>(rInfo.object);
S32 mapIndex = tBlock->getTerrainMapIndex(rInfo.point);
if (mapIndex != -1)
{
MaterialPropertyMap* pMatMap =static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pEntry = pMatMap->getMapEntryFromIndex(mapIndex);
if(pEntry)
{
mMaterialHitType = pEntry->matType;
mMaterialHitFlags = pEntry->matFlags;
}
}The following code (placed around line 452 in interiorcollision.cc (TGE 1.4) adds the material number mapping to the rinfo castray for interiors (not needed for terrain):-
if(inside)
{
info->face = surfaceIndex;
//material mapping code
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const char* pName = mMaterialList->getMaterialName(rSurface.textureIndex);
//const MaterialPropertyMap::MapEntry* pEntry = pMatMap->getMapEntry(pName);
info->material = pMatMap->getIndexFromName(pName);
if(info->material == -1)
info->material = 0; //no entry, use material 0
//end material mapping code
break;
}To make this more useful (and as I havent written a castray solution for shapes) I added 2 additional member fields to simbase called materialtype and materialflags. These can then be used per object (with the usual net code calls) for material properties or you can use mapping per texture too.
For the effects,I added an array of particle effects to projectile (much like the existing decal code) and made each effect material type number the index of the array for lazy calling.
Material flags I use for effects such as shoot through (decal both sides and dont stop bullet), particle effect but no decal etc etc.
I wont be giving a resource at this time as it is still a work in progress.
#3
02/12/2006 (2:15 pm)
Cool! All it needs is something telling us where to put the first two code blocks, and what to do in the weapon scripts to get it to work, and it'll be all set. :P
#4
06/05/2006 (9:27 am)
David would you mind telling me where you put the first two blocks?
#5
The issue with MaterialPropertyMap for mapping effects is that it is one sided. The effects for a wooden crate hitting a metal wall and a metal crate hitting a metal wall are different. If your needs are for only one type of object hitting multiple other types then this does great.
I designed a material centric class similar to this one myself once until another programmer pointed out to me what should have been obvious. You trigger effects like sound, particles, and even physics based on contacts and the contact type. That changed the design of our system for the better.
I believe i'll be working on a contact based effect database for Torque soon and will try to post it as a resource.
06/05/2006 (10:39 am)
A quick note on this.The issue with MaterialPropertyMap for mapping effects is that it is one sided. The effects for a wooden crate hitting a metal wall and a metal crate hitting a metal wall are different. If your needs are for only one type of object hitting multiple other types then this does great.
I designed a material centric class similar to this one myself once until another programmer pointed out to me what should have been obvious. You trigger effects like sound, particles, and even physics based on contacts and the contact type. That changed the design of our system for the better.
I believe i'll be working on a contact based effect database for Torque soon and will try to post it as a resource.
Associate Kyle Carter