Creating an object with trigger
by Craig Lallathin · in Torque Game Engine Advanced · 02/12/2010 (2:03 am) · 8 replies
I am trying to make it to where when I run into a trigger it creates an object(door) in the game so that the player can not go back the way they came.
Is this possible?
Is this possible?
About the author
#2
Thanks Again
02/13/2010 (12:33 am)
Thanks for the prompt response. I will try to implement this on monday and if I have any questions, hopefully you will be there for me. Thanks Again
#3
I know that this is like a noob question but i am having a brain fart.
I have a question about that line. I know that it is for the location for the object but which direction is which (ex. up, down, left/right).
02/14/2010 (6:23 pm)
"%Door.setTransform("0 0 0");//This will place the new door at location 0 0 0 "I know that this is like a noob question but i am having a brain fart.
I have a question about that line. I know that it is for the location for the object but which direction is which (ex. up, down, left/right).
#4
The first three 0's are the position in the world, or the X Y Z posistions.
The last four are the rotation of the object along it's 3 axises.
Simply place the object in the editor where you want it to appear at and make a note of these 2 parameters.
And combine them in your trigger script like this.
And it will place it exactly where you placed it in the editor.
02/14/2010 (7:19 pm)
The SetTransform("0 0 0") should be more like SetTransform("0 0 0 1 0 0 0").The first three 0's are the position in the world, or the X Y Z posistions.
The last four are the rotation of the object along it's 3 axises.
Simply place the object in the editor where you want it to appear at and make a note of these 2 parameters.
position = "-17.8816 669.321 26"; rotation = "0 0 1 205.692";
And combine them in your trigger script like this.
//position first then rotation.
%Door.setTransform("-17.8816 669.321 26 0 0 1 205.692")And it will place it exactly where you placed it in the editor.
#5
Tried to get the object for item 685, which is not InspectorData!
Tried to get the object for item 685, which is not InspectorData!
Namespace::unlinkClass - cannot unlink namespace parent linkage for Door1
for StaticShapeData.
Error: cannot change namespace parent linkage of Door1 from StaticShapeData to Trigger.
Could not find data block "Door1"
02/14/2010 (8:24 pm)
I put in your code and changed it to the dts file of mine and I get five things that are going wrong:Tried to get the object for item 685, which is not InspectorData!
Tried to get the object for item 685, which is not InspectorData!
Namespace::unlinkClass - cannot unlink namespace parent linkage for Door1
for StaticShapeData.
Error: cannot change namespace parent linkage of Door1 from StaticShapeData to Trigger.
Could not find data block "Door1"
#6
I see one error I made in the script.
You need to change
I just tested it with this correction and it works.
02/14/2010 (9:06 pm)
I see one error I made in the script.
You need to change
if(!%trigger.DoorPlaced)To
if(!%this.DoorPlaced)%trigger is the actual trigger and %this is the triggerdata where the DoorPlaced variable was defined.
I just tested it with this correction and it works.
#7
The code......comment at bottom of code.
////////////////////////////////////////////////////////////////////
datablock StaticShapeData(Door1)
{
shapeFile = "~/data/shapes/door/EnergyBarrier.dts";//Change this to the actual door file location
};
function StaticShapeData::create(%data)
{
%obj = new StaticShape()
{
dataBlock = %data;
};
return %obj;
}
datablock TriggerData(CreateDoor)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
DoorPlaced = false;
};
function CreateDoor::onEnterTrigger(%this,%trigger,%obj)
{
echo("Player in trigger");
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the triger
if(!%this.DoorPlaced)
{
%trigger.DoorPlaced = true;
%Door = new StaticShape()
{
dataBlock = Door1;
};
%Door.setTransform("640.593 702.813 199.912 0 0 -1 59.3808");//This will place the new door at location 0 0 0
}
}
function CreateDoor::onLeaveTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object leaves the %trigger
// area, the object is passed as %obj. The default onLeaveTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onLeaveTrigger(%this,%trigger,%obj);
}
function CreateDoor::onTickTrigger(%this,%trigger)
{
// This method is called every tickPerioMS, as long as any
// objects intersect the trigger. The default onTriggerTick
// method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
// every object (whatever it's type) in the same group as the trigger.
// You can iterate through the objects in the list by using these
// methods:
// %this.getNumObjects();
// %this.getObject(n);
Parent::onTickTrigger(%this,%trigger);
}
When I name the trigger I have used Door1, EnergyBarrier, DBarrier, and a few others.
Tried to get the object for item 685, which is not InspectorData!---red
Tried to get the object for item 685, which is not InspectorData!---red
creating path editor/newObject.cs---grey
when I run through trigger it says - Could not find data block "Door1"
02/17/2010 (5:10 pm)
I have a question Bill. When you put your trigger in the game and this works for you are you naming it Door1 because that is the name of your object or could I use just some random name on the trigger?The code......comment at bottom of code.
////////////////////////////////////////////////////////////////////
datablock StaticShapeData(Door1)
{
shapeFile = "~/data/shapes/door/EnergyBarrier.dts";//Change this to the actual door file location
};
function StaticShapeData::create(%data)
{
%obj = new StaticShape()
{
dataBlock = %data;
};
return %obj;
}
datablock TriggerData(CreateDoor)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
DoorPlaced = false;
};
function CreateDoor::onEnterTrigger(%this,%trigger,%obj)
{
echo("Player in trigger");
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the triger
if(!%this.DoorPlaced)
{
%trigger.DoorPlaced = true;
%Door = new StaticShape()
{
dataBlock = Door1;
};
%Door.setTransform("640.593 702.813 199.912 0 0 -1 59.3808");//This will place the new door at location 0 0 0
}
}
function CreateDoor::onLeaveTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object leaves the %trigger
// area, the object is passed as %obj. The default onLeaveTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onLeaveTrigger(%this,%trigger,%obj);
}
function CreateDoor::onTickTrigger(%this,%trigger)
{
// This method is called every tickPerioMS, as long as any
// objects intersect the trigger. The default onTriggerTick
// method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
// every object (whatever it's type) in the same group as the trigger.
// You can iterate through the objects in the list by using these
// methods:
// %this.getNumObjects();
// %this.getObject(n);
Parent::onTickTrigger(%this,%trigger);
}
When I name the trigger I have used Door1, EnergyBarrier, DBarrier, and a few others.
Tried to get the object for item 685, which is not InspectorData!---red
Tried to get the object for item 685, which is not InspectorData!---red
creating path editor/newObject.cs---grey
when I run through trigger it says - Could not find data block "Door1"
#8
You just have to make sure it is defined before you call it.
There have been some times when I needed to define a datablock in a script file separate from the script trying to call it.
I am not sure why this happens be it has happened to me before.
Try creating a script file called doors.cs and put the door datablock definition in it and exec that file before you exec the file where the trigger is.
Also take a look at your console.log file and make sure no compile errors or loading errors occurred.
02/17/2010 (10:21 pm)
You can call the datablock whatever you want to.You just have to make sure it is defined before you call it.
datablock StaticShapeData(EnergyBarrierDoor)
{
shapeFile = "~/data/shapes/door/EnergyBarrier.dts";//Change this to the actual door file location
};
datablock StaticShapeData(EnergyBarrierDoor2)
{
shapeFile = "~/data/shapes/door/EnergyBarrier.dts";//Change this to the actual door file location
};
datablock StaticShapeData(door)
{
shapeFile = "~/data/shapes/door/EnergyBarrier.dts";//Change this to the actual door file location
};These are all valid definitions for the datablocks.There have been some times when I needed to define a datablock in a script file separate from the script trying to call it.
I am not sure why this happens be it has happened to me before.
Try creating a script file called doors.cs and put the door datablock definition in it and exec that file before you exec the file where the trigger is.
Also take a look at your console.log file and make sure no compile errors or loading errors occurred.
Torque Owner Bill Vee
datablock StaticShapeData(Door1) { category = "Doors"; shapeFile = "~/data/shapes/door/door.dts";//Change this to the actual door file location maxDamage = 100; destroyedLevel = 90; }; function StaticShapeData::create(%data) { %obj = new StaticShape() { dataBlock = %data; }; return %obj; } datablock TriggerData(CreateDoor) { // The period is value is used to control how often the console // onTriggerTick callback is called while there are any objects // in the trigger. The default value is 100 MS. tickPeriodMS = 100; DoorPlaced = false; }; function CreateDoor::onEnterTrigger(%this,%trigger,%obj) { // This method is called whenever an object enters the %trigger // area, the object is passed as %obj. The default onEnterTrigger // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on // every object (whatever it's type) in the same group as the trigger. Parent::onEnterTrigger(%this,%trigger,%obj); if(!%trigger.DoorPlaced) { %trigger.DoorPlaced = true; %Door = new StaticShape() { dataBlock = Door1; }; %Door.setTransform("0 0 0");//This will place the new door at location 0 0 0 } } function CreateDoor::onLeaveTrigger(%this,%trigger,%obj) { // This method is called whenever an object leaves the %trigger // area, the object is passed as %obj. The default onLeaveTrigger // method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on // every object (whatever it's type) in the same group as the trigger. Parent::onLeaveTrigger(%this,%trigger,%obj); } function CreateDoor::onTickTrigger(%this,%trigger) { // This method is called every tickPerioMS, as long as any // objects intersect the trigger. The default onTriggerTick // method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on // every object (whatever it's type) in the same group as the trigger. // You can iterate through the objects in the list by using these // methods: // %this.getNumObjects(); // %this.getObject(n); Parent::onTickTrigger(%this,%trigger); }Put it in a script file and make sure you exe it in your start up code.When the player enters the trigger the door will be created and moved to the location you specify.