How to Instantiate Triggers
by Eros Carvalho · in Torque Game Engine · 04/20/2005 (1:13 pm) · 13 replies
I need to create triggers when the game is running.. this is some like land mine triggers... I randomize a position on terrain and generate a trigger there.. but when I try to create this trigger, I receive a warning that says that my trigger object cannot be instantiate cause its a non-conobject ... I alread looked at forums, and my script is execing fine.. In mission editor I can create the trigger and it works...
here is my script to create the trigger:
My datablock is a simple trigger:
here is my script to create the trigger:
function LandMine::Create()
{
%dest = GetRandomPosition();
%minetrigger = new LandMineTrigger()
{
position = %dest;
};
MissionCleanup.add(%minetrigger);
}My datablock is a simple trigger:
datablock TriggerData(LandMineTrigger)
{
tickPeriodMS = 100;
};
#2
04/20/2005 (2:18 pm)
Sorry.. but this dont worked here.. the error continue.. :(
#3
Edit: Typo and missing word.
04/20/2005 (2:29 pm)
Try Matt Fairfax's version again, but change "new LandMineTrigger" to "new Trigger":%minetrigger = new Trigger()
{
position = %dest;
datablock = LandMineTrigger;
};Edit: Typo and missing word.
#5
04/20/2005 (2:43 pm)
Whoops! Good catch =) Silly copy/paste bugs =P
#6
But something is weird.. There is ok, creating the landmines.. but If I open missioneditor and select one of these landmine triggers created, the Torque crashes... :(
And, If I enter in one of these landmines they dont work.. but if I enter in some landmines created using missioneditor it works fine.
04/20/2005 (2:47 pm)
;)But something is weird.. There is ok, creating the landmines.. but If I open missioneditor and select one of these landmine triggers created, the Torque crashes... :(
And, If I enter in one of these landmines they dont work.. but if I enter in some landmines created using missioneditor it works fine.
#7
04/20/2005 (2:52 pm)
Try this:%minetrigger = new Trigger()
{
position = %dest;
datablock = LandMineTrigger;
[b]polyhedron = "0.5 0.5 -0.5 0.5 0.0 0.0 0.0 -0.5 0.0 0.0 0.0 1.0";[/b]
}
#8
04/20/2005 (4:08 pm)
Haha, good catch, Manoel. Ok, now this is getting funny. How many people more must chime in and add a line before the thing works completely? =)
#9
Might want to put in:
04/20/2005 (11:50 pm)
I'm guessing the polyhedron string there defines the shape of the trigger area. How exactly does that work? How do you create a box or a spehere?Might want to put in:
%minetrigger = new Trigger()
{
position = %dest;
datablock = LandMineTrigger;
rotation = "0 0 0 0";
scale = "1 1 1";
polyhedron = "0.5 0.5 -0.5 0.5 0.0 0.0 0.0 -0.5 0.0 0.0 0.0 1.0";
}
#10
Sorry for the delay on reply.
04/25/2005 (10:43 am)
Thanks guys! Now it worked, only remember that need a ; on block end. :PSorry for the delay on reply.
#11
Thats just my guess but it does seem to make alot of sense.
Therefore if you wanted say a cube, you MIGHT get away with this....
%world = "0.5 0.5 -0.5";
%rotation ="0.5 0.0 0.0";
%size = "0.0 -0.5 0.0";
%polyheadron = %world @ %rotation @ %size;
Again like I said this is only my best guess, it might in fact be better to create the object as-is and dump it to see if there is a cube method of some sort.
04/25/2005 (10:59 am)
Your polyheadron is just a vector, the first three appear to be x,yz world cordinates, the next three are rotations on it's central axis, The others would probably be dimensions of the faces out from the absolute center of the object....Thats just my guess but it does seem to make alot of sense.
Therefore if you wanted say a cube, you MIGHT get away with this....
%world = "0.5 0.5 -0.5";
%rotation ="0.5 0.0 0.0";
%size = "0.0 -0.5 0.0";
%polyheadron = %world @ %rotation @ %size;
Again like I said this is only my best guess, it might in fact be better to create the object as-is and dump it to see if there is a cube method of some sort.
#12
This is my function to create a landmine:
The trigger is working ok.. but my problem now, is that the position isnt the center of the objects... so my trigger and my shape, isnt in the same _real_ position, they only have one corner in same position.. how can I find the center position of some object or any other way to put my shape inside my trigger?
thanks again ;)
04/25/2005 (1:22 pm)
Other problem not related to this thread.. But I dont want to create a new one just for a small issue..This is my function to create a landmine:
function LandMine::Create()
{
%dest = Rescue::GetRandomPosition();
%rot = getRandom(360);
%rotation = "0 0 1" SPC %rot;
%shape = new TSStatic()
{
position = %dest;
rotation = %rotation;
shapeName = "rescue/data/shapes/landmine/landmine.dts";
};
MissionCleanup.add(%shape);
%mine = new Trigger()
{
position = %dest;
datablock = LandMineTrigger;
rotation = %rotation;
scale = "3 3 3";
polyhedron = "0.5 0.5 -0.5 0.5 0.0 0.0 0.0 -0.5 0.0 0.0 0.0 1.0";
};
%mine.shape = %shape;
MissionCleanup.add(%mine);
}The trigger is working ok.. but my problem now, is that the position isnt the center of the objects... so my trigger and my shape, isnt in the same _real_ position, they only have one corner in same position.. how can I find the center position of some object or any other way to put my shape inside my trigger?
thanks again ;)
#13
05/06/2005 (9:04 pm)
Yes... I'd really love to know myself >.>... *hides from Matt*
Associate Matt Fairfax
PopCap
%minetrigger = new LandMineTrigger() { position = %dest; [b]datablock = LandMineTrigger;[/b] };