Trigger Arrays
by Austin Whitlatch · in Technical Issues · 04/16/2008 (8:12 pm) · 10 replies
I am trying to make a game where a set of portals are placed around a map. So far I have figured out how to get the trigger to set you to a stationary position (hardcoding the vector... ghetto but works). What I want to know is how to make portal1 make the player appear at portal2. Here is my code so far:
datablock TriggerData(PortalTrigger)
{
tickPeriodMS = 100; //how many ms it ticks between checking when in trigger.
};
function PortalTrigger1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj); //on enter trigger code
%obj.setTransform("0 0 300 1 0 0 0"); //The center of the map... please help me here
}I know to send to another portal it will be something like: %obj.setTransform(trigger2.getTransform()); //something like this?What I would like would be an array set in the *.mis file and each portal even portal will send you to the next odd portal and each odd portal will send you to the previous even portal (portal0 <=> portal1, portal2<=>portal3, etc). Is there a way to set up an array of portals in a .mis file and how would I be able to transport the player. I would like to refrain from making 20 triggers (that wouldn't be fun ><). Can someone help me with an idea?
About the author
#2
in portals.cs
In my *.mis file I added this: (this is set up for stronghold)
Ok, All I had to do is place them in stronghold. Then what I did is added a dynamic field in each of them called 'placement'. This holds what trigger they are. Then you just call %trigger.placement and it will return which portal it is. While it will end up being a giant case statement, this still will work :). Not as elegant as the array but not as ghetto as the other ways that have been tempting to implement lol. Thanks so much for the reply!
04/16/2008 (9:33 pm)
Good news Lee, Just figured it out on my own lol. Here's the code for it: in portals.cs
datablock TriggerData(PortalTrigger)
{
tickPeriodMS = 100; //how many ms it ticks between checking when in trigger.
};
function PortalTrigger::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj); //on enter trigger code
if(%trigger.placement==1)
{
echo(trigger2.getTransform());
%obj.setTransform(trigger2.getTransform());
}
}In my *.mis file I added this: (this is set up for stronghold)
new Trigger(trigger1) {
canSaveDynamicFields = "1";
position = "323.363 304.363 216.375";
rotation = "1 0 0 0";
scale = "1 5.1655 1";
dataBlock = "PortalTrigger";
polyhedron = "0.0 0.0 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 1.0";
placement = "1"; //dynamic field
};
new Trigger(trigger2) {
canSaveDynamicFields = "1";
position = "327.163 199.763 204.375";
rotation = "1 0 0 0";
scale = "1 5.1655 1";
dataBlock = "PortalTrigger";
polyhedron = "0.0 0.0 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 1.0";
placement = "2"; //dynamic field
};Ok, All I had to do is place them in stronghold. Then what I did is added a dynamic field in each of them called 'placement'. This holds what trigger they are. Then you just call %trigger.placement and it will return which portal it is. While it will end up being a giant case statement, this still will work :). Not as elegant as the array but not as ghetto as the other ways that have been tempting to implement lol. Thanks so much for the reply!
#3
If your simGroup's name is something like "PortalGroup" you can transport your player between the previous trigger and next trigger by
hm.... I have NOT tested the code but hopefully you should get the idea.
Aun.
EDIT* added NOT
04/16/2008 (9:35 pm)
Create a simGroup in the mission file and within the simGroup create a group of triggers. If your simGroup's name is something like "PortalGroup" you can transport your player between the previous trigger and next trigger by
function PortalTrigger1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
%count = PortalGroup.getCount();
for ( %i = 0 ; %i < %count ; %i++)
{
%tPort = PortalGroup.getObject ( %i ) ;
if ( %tPort.getId() == %trigger.getId() )
{
%index = %i ;
break;
}
}
// go to previous trigger
if ( %index > 0 )
%transPos = PortalGroup.getObject ( %index - 1 ).getTransform() ;
// go to next trigger
if ( %index < %count -1)
%transPos = PortalGroup.getObject ( %index + 1 ).getTransform() ;
}hm.... I have NOT tested the code but hopefully you should get the idea.
Aun.
EDIT* added NOT
#4
04/16/2008 (9:39 pm)
Thanks man, this will definitely help out. This seems the best way to do it with larger amounts of portals. I do appreciate it :).
#5
Aun's way is superior to both of ours, though, I think.
04/16/2008 (9:43 pm)
Austin, that's great, and thanks for sharing your work!Aun's way is superior to both of ours, though, I think.
#6
04/16/2008 (9:49 pm)
I do agree, The only issue I have ran into is when you do a portal BACK to where you came from. I knew this was going to be an issue due to the fact you are being ported DIRECTLY onto the portal (thus causing you to loop back to the original portal). All I have to figure out now is how to create an offset based on the characters current direction (this way it looks more natural when popping out on the other side). If anyone has suggestions on that I'd love to know how.
#7
04/16/2008 (9:59 pm)
I do agree, The only issue I have ran into is when you do a portal BACK to where you came from. I knew this was going to be an issue due to the fact you are being ported DIRECTLY onto the portal (thus causing you to loop back to the original portal). All I have to figure out now is how to create an offset based on the characters current direction (this way it looks more natural when popping out on the other side). If anyone has suggestions on that I'd love to know how.
#8
Again, I have NOT tested the code. Let me know if this works.
Aun.
04/16/2008 (10:03 pm)
function PortalTrigger1::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
if ( %obj.enterTrigger ) return ;
%obj.enterTrigger = true ;
%count = PortalGroup.getCount();
for ( %i = 0 ; %i < %count ; %i++)
{
%tPort = PortalGroup.getObject ( %i ) ;
if ( %tPort.getId() == %trigger.getId() )
{
%index = %i ;
break;
}
}
// go to previous trigger
if ( %index > 0 )
%transPos = PortalGroup.getObject ( %index - 1 ).getTransform() ;
// go to next trigger
if ( %index < %count -1)
%transPos = PortalGroup.getObject ( %index + 1 ).getTransform() ;
}function PortalTrigger1::onLeaveTrigger(%this,%trigger,%obj)
{
%obj.enterTrigger = false
}Again, I have NOT tested the code. Let me know if this works.
Aun.
#9
04/16/2008 (10:04 pm)
I do agree, The only issue I have ran into is when you do a portal BACK to where you came from. I knew this was going to be an issue due to the fact you are being ported DIRECTLY onto the portal (thus causing you to loop back to the original portal). All I have to figure out now is how to create an offset based on the characters current direction (this way it looks more natural when popping out on the other side). If anyone has suggestions on that I'd love to know how.
#10
The little "Notify me.." checkbox works great, so you don't really need to do that, anyway.
But to respond to your actual post, so much depends on what your game, specifically, needs. It'll be up to you in the long run to sort it out, although of course Aun's second post looks pretty dandy :-)
04/17/2008 (12:05 am)
@Austin: the GG forums have a charming quirk where, after you post, if you hit Reload, it re-posts your post. That's why you see your last post in here three times. Just fyi. The little "Notify me.." checkbox works great, so you don't really need to do that, anyway.
But to respond to your actual post, so much depends on what your game, specifically, needs. It'll be up to you in the long run to sort it out, although of course Aun's second post looks pretty dandy :-)
Torque Owner Lee Latham
Default Studio Name
I think it could be awkard to simply setTransform. What happened when you tried it? You didn't say if there was a problem or not with that.
As for the portal logic, there are probably several ways to do this, and yes, one trigger should be just fine. If you simply name the portals as you suggested, portal1, portal2, etc. then you could simply generate a random number and then to a string concatentate a la:
%destination_portal = "portal" @ %randomresult.
easypeasy. Get the transform of the destination portal using nametoID to get the simID (very handy!) and you're off to the races.