t2dTrigger is not triggering...also lag.
by Storm Kiernan · in Torque Game Builder · 05/24/2011 (8:17 pm) · 4 replies
I have a scenario where I am creating quite a bit of triggers at a time. For instance when one of the players dies: blood gets tossed out (t2dStaticSprite(s)). These objects have no collision on them, but need to have triggers mounted to them. This blood is shot out a small distance from the player (and other enemies that die). There is as much as 8-10 of these blood objects being shot out from any one person or enemy. The idea is that the trigger needs to react when another enemy walks over it. When many enemies start to die or after many triggers have been created there is lag. In addition or more importantly for the moment, the triggers do not work. That is: their callbacks are not being called. Here is the code I am working with:
BloodTriggerDatablock
Blood::onAdd(%this)
The method for shooting out the blood:
The fire method for the blood:
Again, this happens every time anyone dies. I am really struggling with this one...
BloodTriggerDatablock
datablock t2dSceneObjectDatablock(BloodTriggerDatablock)
{
class = BloodTrigger;
canSaveDynamicFields = false;
size = "2.000 2.000";
CollisionActiveSend = false;
CollisionActiveReceive = "1";
MountOffset = "-0.108 0.039";
MountOwned = "1";
MountInheritAttributes = true;
EnterCallback = true;
StayCallback = false;
LeaveCallback = false;
};Blood::onAdd(%this)
function Blood::onAdd(%this)
{
%mountId = %this.mountID;
%bloodTrigger = new t2dTrigger()
{
config = BloodTriggerDatablock;
scenegraph = %this.scenegraph;
mountToId = %mountId;
};
}The method for shooting out the blood:
function Person::bleed(%this)
{
for(%i = 0; %i < 15; %i++)
{
%blood = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
config = BloodDatablock;
Position = %this.position;
};
%randomAngle = getRandom(0, 360);
%randomAngle = mDegToRad(%randomAngle);
%blood.fire(%randomAngle);
}
}The fire method for the blood:
function Blood::fire(%this, %angle)
{
%this.layer = 1;
%this.imageMap = "bloodImageMap";
%this.setSize(3.2, 3.2);
%speed = %this.speed;
//relatively sure that the constant doesn't have to be 3.14
//it exists purely to make sure none of the values are too close to 0
//the speed is a scalar that helps modify...speed...
%velX = getRandom(-%angle - 3.14, %angle + 3.14) * %speed;
%velY = getRandom(-%angle - 3.14, %angle + 3.14) * %speed;
%this.setLinearVelocity(%velX, %velY);
// Use the camera view bounds as the basis for the missile's world limits
%cameraViewBounds = sceneWindow2D.getCurrentCameraArea();
%this.setWorldLimit( kill, getword(%cameraViewBounds, 0) - (%this.getWidth() / 2),
getword(%cameraViewBounds, 1) - (%this.getHeight() / 2),
getword(%cameraViewBounds, 2) + (%this.getWidth() / 2),
getword(%cameraViewBounds, 3) + (%this.getHeight() / 2)
);
%this.schedule(1500, "stop");
}
function Blood::stop(%this)
{
%this.setLinearVelocity(0, 0);
%this.stopped = true;
}Again, this happens every time anyone dies. I am really struggling with this one...
#2
05/25/2011 (9:08 am)
What is the recommended way to attach triggers to objects. The main objective here is to create a trigger zone around each piece of blood so that when another enemy walks over it, there is some cause and effect (not physics).
#3
As to lags, you may want to create fixed amount of blood objects and then reuse them (place object -> hide it after some time -> place again somewhere else, and so on). There are other improvements possible, but this alone should do too.
05/25/2011 (12:24 pm)
Use mount() function. Do a search trough documentation shipped with the engine, it's description should be under t2dSceneObject section.As to lags, you may want to create fixed amount of blood objects and then reuse them (place object -> hide it after some time -> place again somewhere else, and so on). There are other improvements possible, but this alone should do too.
#4
05/25/2011 (3:55 pm)
What is the maximum number of colliding/trigger/physics objects that can be on screen at once?
Torque Owner Rpahut