Projectile Particles
by David Byrge · in Torque Game Engine · 01/18/2007 (9:42 am) · 8 replies
I have a projectile particle that I like. When you shoot your weapon dirt flies in the air. The only problem is it does this when you shoot the ground (great), building (not great) and people (really not great). I want blood or a small amount of dust to show when hitting a person. I want my building particle to show when shooting a building. Is there a way to do this? How would the projectile know what it's colliding with? I hope this makes sense.
#2
You can make a blood explosion that appears when it hits the player's bounding box and it looks pretty accurate, however if you want to leave wound marks well then you are looking at something I haven't figured out how to do yet. It is the DTS files and how they perform collisions with that screws up material mapping since you always end up ready from the invisible collision mesh instead of the object.
Only one guy I know that has gotten decals from projectiles on DTS objects so far, and that is John Kabus with his Paintball game, but he is keeping that tech under wraps until they decide what they are going to do.
If you take a look at the materialPropertyMap source files you will see a couple of handy flags to use. I had to modify my projectile code to detect the flags and select the appropriate decals and explosions.
Thats the majority of what I used in the projectile code processTick function. You will have to add all lof the pack and unpack stuff. Then you just use the values during the projectile explode function to use different decals and explosions. If you end up needing more help just throw me an email. Who knows maybe you can get past the stuff I was having problems with.
01/23/2007 (7:40 am)
Yes you can do it that way. I have already done it but it only works right on difs and terrains. Even managed to make armor piecing rounds for difs.You can make a blood explosion that appears when it hits the player's bounding box and it looks pretty accurate, however if you want to leave wound marks well then you are looking at something I haven't figured out how to do yet. It is the DTS files and how they perform collisions with that screws up material mapping since you always end up ready from the invisible collision mesh instead of the object.
Only one guy I know that has gotten decals from projectiles on DTS objects so far, and that is John Kabus with his Paintball game, but he is keeping that tech under wraps until they decide what they are going to do.
If you take a look at the materialPropertyMap source files you will see a couple of handy flags to use. I had to modify my projectile code to detect the flags and select the appropriate decals and explosions.
if( rInfo.object->getTypeMask() & TerrainObjectType )
{
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)
{
pMatType = pEntry->matType;
}
}
}
else if( rInfo.object->getTypeMask() & InteriorObjectType )
{
MaterialPropertyMap* pMatMap = static_cast<MaterialPropertyMap*>(Sim::findObject("MaterialPropertyMap"));
const MaterialPropertyMap::MapEntry* pMatEnt = pMatMap->getMapEntryFromIndex(rInfo.material);
if (pMatEnt)
{
pMatType = pMatEnt->matType;
pMatFlag = pMatEnt->matFlags;
}Thats the majority of what I used in the projectile code processTick function. You will have to add all lof the pack and unpack stuff. Then you just use the values during the projectile explode function to use different decals and explosions. If you end up needing more help just throw me an email. Who knows maybe you can get past the stuff I was having problems with.
#3
01/23/2007 (6:11 pm)
Wouldn't it be easier to obtain the object type rather than the material type? E.g. terrainObjectType, interiorObjectType, playerObjectType etc...
#4
@Tim - Would you mind giving me a more detailed description of what you are talking about. I like where you are going.
I really appreciate all of your input everyone. Thanks.
01/23/2007 (7:09 pm)
Just an FYI - I am using the FX Pack1 from Games Extract. They have different projectiles that can be used for different weapons. @Tim - Would you mind giving me a more detailed description of what you are talking about. I like where you are going.
I really appreciate all of your input everyone. Thanks.
#5
Go into your projectile "onCollision" function & add this line:
Now start shooting at stuff and check the console. It will report what type of object you have hit.
E.g.
- InteriorInstance
- TerrainBlock
- Player
- TSStatic
- StaticShape
I imagine you could do something like this for the projectile datablock once the necessary source code changes were made:
So, in source code (projectile.cc) you would need to:
1) Register your different explosion fields in the projectile datablock.
2) Determine the type of object the projectile hit & play the corresponding explosion.
Does this sound like what you're after?
01/23/2007 (7:47 pm)
Well, from what I gather you don't want nor need explosions per material type. You want a different explosion per object type.Go into your projectile "onCollision" function & add this line:
echo(%col.getclassName());
Now start shooting at stuff and check the console. It will report what type of object you have hit.
E.g.
- InteriorInstance
- TerrainBlock
- Player
- TSStatic
- StaticShape
I imagine you could do something like this for the projectile datablock once the necessary source code changes were made:
datablock ProjectileData(someProjectile)
{
projectileShapeName = "~/data/shapes/weapon/projectile.dts";
[b]defaultExplosion = genericExplosion;[/b]
[b]terrainExplosion = dirtExplosion;[/b]
[b]waterExplosion = splashExplosion;[/b]
[b]playerExplosion = bloodExplosion;[/b]
[b]interiorExplosion = rockExplosion;[/b]
directDamage = 10;
radiusDamage = 0;
damageRadius = 0;
areaImpulse = 0;
muzzleVelocity = 500;
velInheritFactor = 0.3;
armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = false;
gravityMod = 0.80;
};So, in source code (projectile.cc) you would need to:
1) Register your different explosion fields in the projectile datablock.
2) Determine the type of object the projectile hit & play the corresponding explosion.
Does this sound like what you're after?
#6
A problem occurs from doing things the way you suggest. If you do use the object type instead of material mapping then how would you distinguish between when a bullet hits a wooden wall or a metal wall? Both of these walls would be an InteriorObjectType.
@David Byrge
Using the object type will work fine as long as you have no need to distinguish the explosion type further then their restrictive types. Depending on your individual needs you may have to use a combination of the above ideas.
01/23/2007 (8:48 pm)
@Tim HeldnaA problem occurs from doing things the way you suggest. If you do use the object type instead of material mapping then how would you distinguish between when a bullet hits a wooden wall or a metal wall? Both of these walls would be an InteriorObjectType.
@David Byrge
Using the object type will work fine as long as you have no need to distinguish the explosion type further then their restrictive types. Depending on your individual needs you may have to use a combination of the above ideas.
#7
01/24/2007 (4:26 am)
The method I posted will allow you to tell between the metal and wooden and so on, But if you only need somthing simple like what is a player, or building, or vehicle then Tim's is the easier choice.
#8
I think at some point I would like to maybe move towards having the bullet distinguish the material type but for right now I want to see the change between ground, building, water and person. Thank you for your insight though. I also re-read your first post. Good information.
@Tim-
I will use this method and report my success in doing so with screen shots. Thank you.
@Ron- Your method seems to be over my head at the moment. I will get there one day. :)
01/24/2007 (5:31 am)
@ Joshua -I think at some point I would like to maybe move towards having the bullet distinguish the material type but for right now I want to see the change between ground, building, water and person. Thank you for your insight though. I also re-read your first post. Good information.
@Tim-
I will use this method and report my success in doing so with screen shots. Thank you.
@Ron- Your method seems to be over my head at the moment. I will get there one day. :)
Torque Owner Joshua Jewell
Here is the scripting part of the code, It determines which materials corespond to which sounds inside of the engine:
Then inside of the Player's playFootstepSound method we see this code:
switch (sound) { case 0: // Soft alxPlay(mDataBlock->sound[PlayerData::FootSoft], &footMat); break; case 1: // Hard alxPlay(mDataBlock->sound[PlayerData::FootHard], &footMat); break; case 2: // Metal alxPlay(mDataBlock->sound[PlayerData::FootMetal], &footMat); break; case 3: // Snow alxPlay(mDataBlock->sound[PlayerData::FootSnow], &footMat); break; default: //Hard alxPlay(mDataBlock->sound[PlayerData::FootHard], &footMat); break; }I believe a little bit above this code is where it gets the sound from the material mapping that was set up in script.If you know your way around the engine then you can modify the Projectile's explode method to play variable explosions. Here is some of the code that picks the explosions datablock:
if (mDataBlock->waterExplosion && pointInWater(p)) { pExplosion = new Explosion; pExplosion->onNewDataBlock(mDataBlock->waterExplosion); } else if (mDataBlock->explosion) { pExplosion = new Explosion; pExplosion->onNewDataBlock(mDataBlock->explosion); }As you can see it already plays different explosions if the projectile hits on land or in the water. It should not be too much additional work to make it depend on building or player textures.