How to Spawn a decal with script - info
by Steve Acaster · in Torque 3D Professional · 11/25/2010 (3:30 pm) · 10 replies
I've got a basic hit-prediction scripted and whilst I can spawn applicable damage, explosion, etc at the end of the raycast, I've not worked out how to slap a decal at the position.
Anyone any ideas on spawning a decal with script? I'd hoped it would be a simple %decal = new decalData, datablock =, position=, etc but apparently it isn't ... or at least nothing happens and nothing in the console.
[edit]
Answer below!
Moved to useful Threads
Anyone any ideas on spawning a decal with script? I'd hoped it would be a simple %decal = new decalData, datablock =, position=, etc but apparently it isn't ... or at least nothing happens and nothing in the console.
[edit]
Answer below!
Moved to useful Threads
About the author
One Bloke ... In His Bedroom ... Trying To Make Computer Games ... eventually ...
#2
11/25/2010 (10:57 pm)
Thanks for the pointer, foolishly I looked in the other code files but not that one ... not that I got it working properly ... keeps appearing at origin ...
#3
11/25/2010 (11:12 pm)
Okay got it working ... on flat ground plane ... but not objects ... I'm thinking that's what the normal is for ...
#4
11/25/2010 (11:32 pm)
Which is the transform of the impact position ... yay ... still a little stretched on certain surfaces ... I'm wondering if that's due to the truncation in the numbers ... e-00
#5
And all appears well in the world of scripting bullet holes on to raycasts.
Moved to "useful threads" forum.
:)
11/25/2010 (11:42 pm)
Apparently not - it was the rotation setting stretching things over too far, set to zero all is fine.%impact = "0.215927 19.9602 2.98508 -1 2.98023e-008 8.9407e-009";
%rot = getwords(%impact, 3, -1);
echo("decal wanted at normal rotation " @ %rot);
%pos = getwords(%impact, 0, 2);
echo("decal wanted at pos " @ %pos);
//decalManagerAddDecal( %position, %normal, %rotation, %scale, %decalData, %immortal);
decalManagerAddDecal(%pos, %rot, 0.0, 1.0, smallimpactsDecal, false);And all appears well in the world of scripting bullet holes on to raycasts.
Moved to "useful threads" forum.
:)
#6
This one goes in right there with the rest of the small gems.
Thanks Steve.
11/26/2010 (12:55 am)
You should consider writing a book with all the tricks you figure out! I have a number of these printed out for instant reference.This one goes in right there with the rest of the small gems.
Thanks Steve.
#7
11/26/2010 (6:58 am)
Yes,the rotation is an angle (in radians),because the AngAxisF class is used for it.
#8
maybe you can help me write a small function that lays a scorch decal, at the spot where a box has been destroyed, upon its scheduled delete?
it would really be a huge help, been struggling with it
11/27/2010 (5:05 pm)
@Steve,maybe you can help me write a small function that lays a scorch decal, at the spot where a box has been destroyed, upon its scheduled delete?
it would really be a huge help, been struggling with it
#9
11/27/2010 (6:20 pm)
i second konrad's post. your tricks and help you provide are invaluable.
#10
I'd think a raycast down from the centre (or at least above) the destroyed object from it's damage/onDamage/onDestroyed/etc fucntion would do the trick.
Been partying ... brain a little fuzzy ... but off the top of my head without testing ...
11/28/2010 (4:35 pm)
@DeepI'd think a raycast down from the centre (or at least above) the destroyed object from it's damage/onDamage/onDestroyed/etc fucntion would do the trick.
Been partying ... brain a little fuzzy ... but off the top of my head without testing ...
//I like my typemasks collected into a big global,
//saves typing them out individually everytime
$Obstacles =
$TypeMasks::VehicleObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::StaticTSObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::ForestObjectType; // InteriorObjectType replaced
Function Your_Class_Thing_Here::onCollision(%this, %col, %etc)
{
if(%this.getDamagelevel() >= %this.maxDamage)
{
%start = %this.getWorldBoxCenter;
%end = VectorAdd(%start, "0 0 -5");
//how big is the box? No point sending a raycast off for 20km
//so 5 units/metres here
%targetsearch = containerRayCast(%start, %end, $Obstacles, %this.getID());
%impactpoint = firstWord(%targetsearch);
%pos = getwords(%targetsearch, 1,6);
//do your explosion FX here, particles, audio etc
if(%impactpoint != false)
{
%rot = getwords(%pos, 3, -1);
//decalManagerAddDecal(%position,%normal,%rotation,%scale,%decalData,%immortal);
decalManagerAddDecal(%pos, %rot, 0.0, 1.0, ScorchBigDecal, false);
}
}
}
Torque Owner Ivan Mandzhukov
Liman3D
There is a method decalManagerAddDecal.
You can use decalManagerRemoveDecal also...
I'm not really sure,but decals should be instantiated on the client side.