<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
	xmlns="http://purl.org/rss/1.0/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel rdf:about="http://feeds.garagegames.com/rss/blogs/developer/116044/">
		<title>Blog for Austin Whitlatch at GarageGames.com</title>
		<description>Blog feeds for Gamers and Developers in the GarageGames community.</description>
		<link>http://www.garagegames.com/</link>
		<image rdf:resource="http://www.garagegames.com/images/GarageGames_logo_small_w.gif" />
		<dc:date>2008-11-22T11:43:59+00:00</dc:date>
		<items>
			<rdf:Seq>
				<rdf:li rdf:resource="http://www.garagegames.com/blogs/116044/14615"/>
			</rdf:Seq>
		</items>
	</channel>
	<item rdf:about="http://www.garagegames.com/blogs/116044/14615">
		<dc:format>text/html</dc:format>
		<dc:date>2008-04-18T04:29:22+00:00</dc:date>
		<dc:creator>Austin Whitlatch</dc:creator>
		<title>Portal Tutorial</title>
		<link>http://www.garagegames.com/blogs/116044/14615</link>
		<description>Earlier this week I was having issues with getting a portal system to work (player standing at X,Y and being transferred to X1,Y1). The idea and concept were simple enough, but a little daunting. This code will show you how I was able to implement and I hope it helps you guys out in your games as well.&lt;br&gt;NOTE: this implementation is only good for single player games.&lt;br&gt;Create a new file in the server folder called portalTrigger.cs.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class='codeblock'&gt;&lt;pre&gt;$canTeleport = true;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;This is a global variable that is used to denote when a player can travel through a portal. The reason for this is when traveling through a two way portal, the player needs a small amount of time (close to 1 second) to get out of the telepad so he his not teleported back and forth either infinitely or until the character ends up out of the portal range. &lt;br&gt;&lt;br&gt;&lt;div class='codeblock'&gt;&lt;pre&gt;function resetTeleport()&lt;br&gt;{&lt;br&gt;   $canTeleport = true;&lt;br&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;This function resets the global variable back to true. Used later in the code.&lt;br&gt;&lt;br&gt;&lt;div class='codeblock'&gt;&lt;pre&gt;[code]&lt;br&gt;datablock TriggerData(PortalTrigger)&lt;br&gt;{&lt;br&gt;   tickPeriodMS = 100; //how many ms it ticks between checking when in trigger.&lt;br&gt;};&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;This code is taken directly from the default triggers.cs file. Just controls how often it will check. Here it is 1/10 of a second.&lt;br&gt;&lt;br&gt;&lt;div class='codeblock'&gt;&lt;pre&gt;function PortalTrigger::onEnterTrigger(%this,%trigger,%obj)&lt;br&gt;{&lt;br&gt;   Parent::onEnterTrigger(%this,%trigger,%obj); //on enter trigger code&lt;br&gt;   if(%trigger.placement==1 &amp;amp;&amp;amp; $canTeleport)&lt;br&gt;   {&lt;br&gt;      $canTeleport = false;&lt;br&gt;      schedule(1000, %obj, resetTeleport);&lt;br&gt;      echo(trigger2.getTransform());&lt;br&gt;      %obj.setTransform(trigger2.getTransform());&lt;br&gt;   }&lt;br&gt;   if(%trigger.placement==2 &amp;amp;&amp;amp; $canTeleport)&lt;br&gt;   {&lt;br&gt;      $canTeleport = false;&lt;br&gt;      schedule(1000, %obj, resetTeleport);&lt;br&gt;      echo(trigger1.getTransform());&lt;br&gt;      %obj.setTransform(trigger1.getTransform());&lt;br&gt;   }&lt;br&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;When the player enters the trigger, it finds out exactly which trigger it is on the map. I created a dynamic data field in the map called placement. Each portal has the naming standard of 'trigger' + number. The placement is the number, so trigger1 has placement = 1. Remember, for this code to work, you must put in these dynamic fields within The Torque World creator and saved in the specific *.mis file that you are working with. The schedule that is in the code is there to ensure that a player does not get teleported immediately upon entering the other portal that he was teleported to. It gives the player 1 second (which is plenty of time) to remove themselves from the portal.&lt;br&gt;%obj is in most cases your player (I haven't checked if throwing items through this portal will work, projectiles do not, but items may). %obj.setTransform is setting the players new position, in this case the position of the other portal.&lt;br&gt;&lt;br&gt;I hope this helps some of you in your future games. I'd like to give special thanks to Lee and Aun for helping me out in a forum post I had a while ago. Thanks guys, its people like you that make the TGE community so great.&lt;br&gt;&lt;br&gt;Please feel free to use this code as your own, I just hope someone finds it useful ;)</description>
	</item>
</rdf:RDF>
