So I'm new to TorqueScript and I'm trying to make a trigger for something to happen, however whenever I stand on the brick it never does anything.
I've found this from searching to see if someone else has had the same problem:
function FxDTSBrick::createTrigger(%this, %data)
{
//credits to Space Guy for showing how to create triggers
%t = new Trigger()
{
datablock = %data;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1"; //this determines the shape of the trigger
};
missionCleanup.add(%t);
%boxMax = getWords(%this.getWorldBox(), 3, 5);
%boxMin = getWords(%this.getWorldBox(), 0, 2);
%boxDiff = vectorSub(%boxMax,%boxMin);
%boxDiff = vectorAdd(%boxDiff, "0 0 0.2");
%t.setScale(%boxDiff);
%posA = %this.getWorldBoxCenter();
%posB = %t.getWorldBoxCenter();
%posDiff = vectorSub(%posA, %posB);
%posDiff = vectorAdd(%posDiff, "0 0 0.1");
%t.setTransform(%posDiff);
%this.trigger = %t;
%t.brick = %this;
return %t;
}
... and I'm using this with the brick:
datablock fxDTSBrickData(TestBrickData : brick2x4fData)
{
category = "Test";
subCategory = "Bricks";
uiName = "Test Brick";
};
datablock TriggerData(TestBrickTriggerData)
{
tickPeriodMS = 150;
};
function TestBrickData::onPlant(%this, %obj)
{
%this.createTrigger(TestBrickTriggerData);
}
function TestBrickTriggerData::onEnterTrigger(%this, %trigger, %obj)
{
echo("Player on brick");
}
function TestBrickTriggerData::onLeaveTrigger(%this, %trigger, %obj)
{
echo("Player off brick");
}
function TestBrickTriggerData::onTickTrigger(%this, %trigger, %obj)
{
Parent::onTickTrigger(%this, %trigger);
}
I don't really see what's going wrong. I'm not sure if I'm using %brick.createTrigger(%data); wrong or not... Help?