Doing damage to Static Shape
by JD Scogin · in Torque 3D Beginner · 07/01/2013 (3:36 pm) · 25 replies
I am trying to set up a shape so I can do damage to it. I have tried creating datablock, making it static and dynamic, but when I do, following a tutorial, I there is no collisions set up, so the bullets pass right thru, on both. I know this is possible, because the turret takes damage and you can't walk thru it. I am asking because I have spent about two days trying to figure this out. Here is what I need. I have a tunnel set up. I want to put a static zombie (shape) in the way. I don't what the player to be able to walk thru it. I also want the player to be able to shoot it was a gun and kill it. (or make it disappear). Has anyone done this? Thanks for any help.
Jd
Jd
About the author
#2
07/01/2013 (6:48 pm)
Thanks for the response. Now I have to figure out how to do what you said. If I get this right, it will trigger on being damaged? That is the main thing I am looking for. A static shape that can take damage.
#3
07/01/2013 (6:56 pm)
Why not just spawn the zombie as an AIPlayer with no "AI"? It will be collidable and you should be able to damage it.
#4
07/01/2013 (8:05 pm)
Whoa, something else I don't know how to do. But I will start digging into the docs and see if I can figure it out. The is probably what I want to do. Thanks
#5
07/01/2013 (10:35 pm)
Look in The User Guide section under Scripting->Advanced->RTS Prototype - it should get you pointed in the right direction.
#6
07/02/2013 (3:52 am)
Thanks, I am doing that. Since the MIT version is now open source, maybe someone could fix it. It would make things much better if static shapes could trigger on damage. Destructible objects. Also trigger on collisions. But with these suggestions, maybe I can get it done. Thanks again. Jd
#7
has static shapes that can be triggered
to perform damage along with particle effects
and with some playin around you can change it to be a rigid shape
with destruction stages
only issue then is the particles
should be mounted to the model itself - or use another approach
since a rigid shape can be pushed around and it look just weird
if the particles float in the air and the models itself is already a yard away
07/02/2013 (7:18 am)
the opensourced GMKhas static shapes that can be triggered
to perform damage along with particle effects
and with some playin around you can change it to be a rigid shape
with destruction stages
only issue then is the particles
should be mounted to the model itself - or use another approach
since a rigid shape can be pushed around and it look just weird
if the particles float in the air and the models itself is already a yard away
#8
07/02/2013 (7:39 am)
The TSStatic/StaticShape hierarchy split is a bit of a mess to be honest. We should definitely look into cleaning it up, though Jeff Raab is doing some work on a component entity model for Torque that may make vast chunks of the current hierarchy redundant anyway. Watch that space.
#9
like so often am not sure when this will get in our hands since
it`s all good and fine but since real field testing and exploring it`s possibilities is currently not possible
and who knows what Jeff raab will decide
crowd funding or who knows
when there will be something to work with
so why are we ignoring what we already have?
i mean GMK`s issues where mostly related to obsolote art - since the way the model where constructed doens`t really fit in T3D v3
and ofc code related issues like ragdolls not working or let me reprahse this
they work but are getting weird as soon as you have more then lets say 2-3 ragdoll characters
however thats solveable ;)
and instead of tryin to reinvent the wheel
why not just take what we have and expand on it
it doesn´t really matter if you call it a behaviour or a template
07/02/2013 (8:01 am)
ye saw that but tbhlike so often am not sure when this will get in our hands since
it`s all good and fine but since real field testing and exploring it`s possibilities is currently not possible
and who knows what Jeff raab will decide
crowd funding or who knows
when there will be something to work with
so why are we ignoring what we already have?
i mean GMK`s issues where mostly related to obsolote art - since the way the model where constructed doens`t really fit in T3D v3
and ofc code related issues like ragdolls not working or let me reprahse this
they work but are getting weird as soon as you have more then lets say 2-3 ragdoll characters
however thats solveable ;)
and instead of tryin to reinvent the wheel
why not just take what we have and expand on it
it doesn´t really matter if you call it a behaviour or a template
#10
And, after all, the whole point of a "static shape" is to be static.
07/02/2013 (8:22 am)
I was just pointing out that since he was placing a zombie it would be appropriate for it to be a zombie... er, "I-less" AIPlayer....And, after all, the whole point of a "static shape" is to be static.
#11
07/02/2013 (10:05 am)
Damage to static shapes is quite easy... just take advantage of the inherited Shapebase callbacks -- but keep in mind that TSStatics (different from the StaticShape class) do not enable such callbacks and that is a design decision that we probably aren't going to do away with until such time as we can replace everything Shapebase.
#12
this code will cause performance hit.but not noticeable.
better u use "StaticShape " .using that u will be able to overcome this perfomace hit.code will be like this:
07/02/2013 (5:26 pm)
u can fake it like this:function TSStatic ::damage(%obj, %sourceObject, %position, %amount, %damageType)//%data,
{
if( %obj.damage $="")
%obj.damage=0;
%obj.damage= %obj.damage+%amount;
%particles = new ParticleEmitterNode()
{
position = %position;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "DamageFxNode";
emitter = "GrenadeDebrisFireEmitter";
velocity = ".1";
};
MissionCleanup.add(%particles);
%particles.schedule(5000, "delete");
if(%obj.damage>=100)
{
//do your code to perform work when object completely damaged
obj.delete();//here,i am deleting it
}
}this code will cause performance hit.but not noticeable.
better u use "StaticShape " .using that u will be able to overcome this perfomace hit.code will be like this:
function YourStaticShapeObjectNameOrDatablockName::damage(%obj, %sourceObject, %position, %amount, %damageType)
{
...................
}
#13
07/02/2013 (10:19 pm)
What do you mean by a performance hit if using a TSStatic?
#14
07/03/2013 (5:39 am)
Really some good information here. Thanks everyone for you suggestions. Thanks ashan, I will give that a "shot". I am really glad to see the forum so active.
#15
if( %obj.damage $="") I have tried several things but can't seem to get it right.
Also, where should I exec this from? I have tried for server/games.cs I put it in client.csThis may seem dumb, but I can't figure out how to link it.Thanks
07/03/2013 (11:08 am)
Ashan, a couple of questions. I assume I have to fill in the blank here: if( %obj.damage $="") I have tried several things but can't seem to get it right.
Also, where should I exec this from? I have tried for server/games.cs I put it in client.csThis may seem dumb, but I can't figure out how to link it.Thanks
#16
put together hundreds of TSStatic((each one very much small) then do a explosion over them.and there will happen some slowness.
may be that is because of callback of damage() for hundreads of TSStatic.
if u have only few of them then there will be no lag.
+it depends on configuration and processor load.
so it is better to use staticShape datablock to skip objects that are not under that specific datablock .
****************
"if( %obj.damage $="") "
no.it search for a variable(dynamic field) named "damage" into %obj.
if the object do not have one then for (%obj.damage=0; ) it will create a "damage" .
so keep it as it is.
"if(%obj.damage>=100) "
change 100 with the value for which u want to destroy %obj.
for testing u can add the code at the end of "scriptsserverradiusDamage.cs"
07/03/2013 (7:33 pm)
"What do you mean by a performance hit if using a TSStatic?"put together hundreds of TSStatic((each one very much small) then do a explosion over them.and there will happen some slowness.
may be that is because of callback of damage() for hundreads of TSStatic.
if u have only few of them then there will be no lag.
+it depends on configuration and processor load.
so it is better to use staticShape datablock to skip objects that are not under that specific datablock .
****************
"if( %obj.damage $="") "
no.it search for a variable(dynamic field) named "damage" into %obj.
if the object do not have one then for (%obj.damage=0; ) it will create a "damage" .
so keep it as it is.
"if(%obj.damage>=100) "
change 100 with the value for which u want to destroy %obj.
for testing u can add the code at the end of "scriptsserverradiusDamage.cs"
#17
07/04/2013 (3:38 pm)
Ahsan, I can't get this to work at all. Not sure what I am missing. I removed the particale lines. Just trying to trigger on the shot, but not working. I put it in radiusDamage.cs.
#18
07/04/2013 (3:39 pm)
.
#19
i did those script long time ago to get a feeling of BF4.
so forgot other parts.
that hack needs some more work to do.here is full code:
open
game\scripts\server\projectile.cs
replace ProjectileData::onExplode() with this:
this script was the result of some quick hack.
so better try to understand whole code.
otherwise u will not be able to debug some side effects due to this hack.
07/04/2013 (7:15 pm)
sorry.i did those script long time ago to get a feeling of BF4.
so forgot other parts.
that hack needs some more work to do.here is full code:
function radiusDamage4StaticShapeObjectType(%sourceObject, %position, %radius, %damage, %damageType, %impulse)
{
// Use the container system to iterate through all the objects
// within our explosion radius. We'll apply damage to all ShapeBase
// objects.
InitContainerRadiusSearch(%position, %radius, $TypeMasks::StaticShapeObjectType);
%halfRadius = %radius / 2;
while ((%targetObject = containerSearchNext()) != 0)
{
// if(!%targetObject.isField ("explodeLevel"))
// continue;
// Calculate how much exposure the current object has to
// the explosive force. The object types listed are objects
// that will block an explosion. If the object is totally blocked,
// then no damage is applied.
%coverage = calcExplosionCoverage(%position, %targetObject,
$TypeMasks::InteriorObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::ForceFieldObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::VehicleObjectType);
if (%coverage == 0)
continue;
// Radius distance subtracts out the length of smallest bounding
// box axis to return an appriximate distance to the edge of the
// object's bounds, as opposed to the distance to it's center.
%dist = containerSearchCurrRadiusDist();
// Calculate a distance scale for the damage and the impulse.
// Full damage is applied to anything less than half the radius away,
// linear scale from there.
%distScale = (%dist < %halfRadius)? 1.0 : 1.0 - (((%dist - %halfRadius) / %halfRadius)/100);///-hack.dont know what it do.for now hack is ok?????????????????!!!!!!!!!!!!!!!
// Apply the damage
if( (%damage $="") || (%damage==0) )//hack.in case if weapon's projectile db have no field specified to allow radius damage(lurker,pistol)
{
%damage=10;
}
%targetObject.damage(%sourceObject, %position, %damage * %coverage * %distScale, %damageType);
}
}
function TSStatic ::Damage(%obj, %sourceObject, %position, %amount, %damageType)//%data,
{
if( %obj.damage $="")
%obj.damage=0;
%obj.damage= %obj.damage+%amount;
%particles = new ParticleEmitterNode()
{
position = %position;
rotation = "1 0 0 0";
scale = "1 1 1";
// dataBlock = "DamageFxNode";
emitter = "GrenadeDebrisFireEmitter";
velocity = ".1";
};
%damagedLevel=100;
MissionCleanup.add(%particles);
%particles.schedule(5000, "delete");
if(%obj.damage>=%damagedLevel)
{
//do your code to perform work when object completely damaged
%obj.delete();//here,i am deleting it
}
}open
game\scripts\server\projectile.cs
replace ProjectileData::onExplode() with this:
function ProjectileData::onExplode(%data, %proj, %position, %mod)
{
//echo("ProjectileData::onExplode("@%data.getName()@", "@%proj@", "@%position@", "@%mod@")");
// Damage objects within the projectiles damage radius
if (%data.damageRadius > 0)
{
radiusDamage(%proj, %position, %data.damageRadius, %data.radiusDamage, %data.damageType, %data.areaImpulse);
radiusDamage4StaticShapeObjectType
(%proj, %position, %data.damageRadius, %data.radiusDamage, %data.damageType, %data.areaImpulse);
}
}this script was the result of some quick hack.
so better try to understand whole code.
otherwise u will not be able to debug some side effects due to this hack.
#20
07/04/2013 (8:20 pm)
Wow, Perfect! Works great. I can deal with side effects. I am planing on making short games with not too much in. So this should work fine. And I will dig into the code. I have already been playing with radiusDamage. So I do understand some of it. Thanks, you are Great! I just hope someone adds that to the game. It just seems like it should be there anyway.
Torque Owner DreamPharaoh
Gods and Nemesis
If you want to add collision to a dynamic static shape then you will need to cheat by making an invisible texture and modeling a collision mesh that uses this texture. Do an onAdd command in script to take the object's position (the zombie in your case) and apply it to the invisible textured collision shape. I have used this for doors, breakable walls, and treasure chests.