Game Development Community

Scripting Create Trigger

by Justin Campbell · in Torque 3D Professional · 07/29/2009 (10:40 pm) · 4 replies

I am creating an evaluation project, and of course I am a noob to T3D and GG. Very Simply, I have created my own AI server side script, have bots running around killing %me and %each_other on beta 4. But I am having trouble with the trigger object. I do not want to create them in the editor, as when I spawn certain types of bots to a random location, I want to place a trigger around them. Could I please get a sanity check on this code and maybe a little more understanding on what is required to create a trigger?

function AiModel::newAITrigger(%location, %parent)
{
    error("TriggerBegun");
    %scale = "80 80 80";
    %position = %location;
    %trigger = new Trigger()
    {
        dataBlock = "DefaultTrigger";
        polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
    };
    //echo(%parent.position);
    %position.z -= 40;
    %trigger.position = %position;
    %trigger.setScale(%scale);
    //%parent.trigger = %trigger;
    error("TriggerFinished" @ $trigger.getid());
    return %trigger;
}

#1
07/30/2009 (8:59 am)
Replace this:
%trigger.position = %position;

With this:
%trigger.setTransform(%position);

The attributes only work for write during creation.
#2
07/30/2009 (9:06 am)
the following should work too I think
%position.z -= 40; 
%trigger = new Trigger()  
{  
  dataBlock = "DefaultTrigger";  
  polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1"; 
  position = %position;
  scale = %scale;
};
#3
07/30/2009 (11:29 am)
@Manoel.. Thank you, I understand that the setTransform contains the additional location data, but I am curious if there are other reasons that I see people using the setTransform?

@Marc yes the above also worked

Thank you both very much... obviously I got too excited with T3D and pushed my waking hour limit too far. The attribs were causing trouble. Below is the working code. I hope it makes the life of someone else easier.


function aiModel::AITrigger(%location)
{
    %scale = "80 80 80";
    %position = %location;
    %position.z -= 40;
    %trigger = new Trigger()
    {
        dataBlock = "DefaultTrigger";
        polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
        position = %position;
        scale = %scale;  
    };
    return %trigger;
}
#4
07/30/2009 (12:10 pm)
@Justin: not all classes have setPosition(), and if you pass only a position to setTransform() it doesn't changes the current rotation, so it's essentially the same.