Links

Make a two-way teleport system

Open up more creative ideas with a 2 way teleport system for your game.
Image for post
NOTE: This system has been upgraded. Check here for updated tutorial.​
Note: This system requires your Avatar to die and respawn for it to work. Currently, you cannot do the teleport system without dying so you need to consider this when designing your game.
  • Click the ‘Global Parameters’ buttons at the top of the bar.
  • Click the ‘Controller’ tab
  • Click the ‘Components’ tab. Here we can set the Avatars Health and Death settings.
  • In ‘Health Component’ settings under the ‘Death Event’ field select ‘RespawnToTag’
  • In the ‘Respawn Tag’ add your tag. In this example, we used ‘spawn1’. Any object in the Game with a tag ‘spawn1’ will be used as a spawn point when the Avatar dies.
  • ‘Death Delay’ is how long your Avatar lays dead on the ground for before respawning. We used ‘-2’ in this example because it makes the Avatar respawn instantly without having a dying animation.
  • Changed the default ‘Instant Death Message’ message to anything else so you got full control of when this happens. In this example, we used 'Killx'.
Now when your Avatar dies it will look for the closest object with the tag ‘spawn1’ and spawn your Avatar at that location. If it cannot locate the Tag it will spawn you at your starting or current location.
  • Place down an asset to use as a spawn point. We recommend using a default object of the Game Maker to avoid issues on the client's end. In this example, we used ‘Stone Carving’ as its flat and a good size to manage.
  • Select your spawn point and add a Tag to it named ‘spawn1’
Image for post
Now when the Avatar dies he will spawn on top of that Stone Carving. You can make the object invisible or just push underground just enough to not be seen.
Congratulations you now built respawn location for your game.
Now how does a 2-way teleport system work? Its a little more tricky so lets explore how it’s done.
  • Duplicate your ‘spawn point’ by selecting and press band drag it to your other location where you want the 2-way teleport system to work.
  • Select your each ‘spawn point’ and click the ‘eye’ icon to make the object invisible. Check the screenshot below.
  • Select the spawn points, under the Physics settings select ‘No collision’. this way it won’t get in the way of other objects including the Avatar.
  • Double-check your spawn point Tags match your Avatars Health Component settings. In this example, it’s ‘spawn1’
Image for post
Great! Now we got our 2 spawn points. Now we need something to trigger the Avatars death so the teleport can be used.
As we continue the next steps I want to explain it a little bit then show you how it's done. To get the 2-way teleport system to work correctly we had to use 2 ‘Asker behaviors’ on 2 different objects. Along with other objects as ‘Void Behaviours’ to delete the spawner we don’t need. The ‘first Asker behaviour’ will send a message to trigger the spawner we need to teleport to and the ‘second Asker behaviour ‘kills the Avatar which teleports you to the new spawn point. Let me show you below.
  • We need a lever or button to activate the teleport system. In this example we used the default asset ‘Ancient Lever’ and added one on each side of the teleport system.
  • Add the ‘Asker Behaviour’ to the lever.
  • Add your text you want the player to read giving only one answer and one option. In this example, we used ‘teleportAway’ as the message to send out.
Image for post
For the second Asker, we can use any asset, it won’t be seen. In this example, we used ‘NumPad Switch’ as its a small default asset.
  • Place your object near the lever and give it the ‘Asker Behaviour’
  • Make the ‘Message Required’ = ‘teleportAway’
What happens here is when you interact with the lever it will give you Question 1. When you answer it sends a Message to Question 2 which pops up straight away starting a chain.
  • Set the answer of question 2 to be the Death Message of your Avatar which we set as ‘Killx’ earlier.
Image for post
  • Make the ‘NumPad Switch’ invisible and ‘No Collisions’
Image for post
When you die you will notice it will teleport you to the spawn point below your feet of the lever which is not what we want it to do. We want to go on the other side spawn point but they both have the same tag so what do we do next? We use a ‘Void Behaviour’ to delete the spawn under your feet when you activate the lever. Lets see how this is done below.
  • Bring out another ‘NumPad Switch’ and set to ‘Void Behaviour’
  • Set the ‘NumPad Switch’ to ‘invisible’ and ‘No Collisions’
  • In the ‘Void Behaviour’ settings the Message Required is ‘teleportAway’ which is the first Asker behaviours message that it sends when it’s answered.
  • ‘Blocks Destruction’ = ‘DontDestroy’
  • ‘Assets Destruction’ = ‘OnlyDestroyFromList’
  • ‘Assets List’ here you need to select the asset you used as the teleport. The void will look for the asset in its Red Destroy Area so make sure your teleport is within the borders.
Image for post
Now when you use the teleport you should be teleported to the other side!
But it is still not quite there yet. We might be on the other side, but now we have deleted our first teleport and there are no functions to get back. Let’s dig into how we set this up now.
  • Duplicate the two ‘NumPad Switch’ we made and drag them to the other side to your other teleporter.
Image for post
  • Make sure the ‘NumPad Switch’ with the ‘Void Behaviour’ on the other side has the portal within its Red Destroy Area
  • Change the Message Required to ‘teleportHome’
Image for post
  • Select the other ‘NumPad Switch’ and change the Message Required to ‘teleportHome’
Image for post
  • Select your ‘Ancient Lever’ and change its ‘A1 Broadcast’ message to ‘teleportHome’
Image for post
Now we have set up all the functions to kill off the spawner under your feet and kill you again but this time we got no more spawn points. We killed the Home teleport to get to the Away side. So now we have to find a way to summon the teleport back on the other side for us to get to. Let's see how this is done.
  • Make Another ‘NumPad Switch’ and give it the ‘Asset Spawner Behaviour’
  • Make the ‘NumPad Switch’ invisible and ‘No Collisions’ and place it just above your spawner. See image below.
  • ‘Asset to Spawn’ = ‘Stone Carving’
  • ‘Tags’ = ‘spawn1’ this is how we get our new spawn point.
  • ‘Message required’ = ‘teleportHome’ when you finish with the rest of the settings, duplicate this asset with CTRL + D and drag it to the other side on the other teleporter location and change the message to ‘teleportAway’
  • ‘Physics Type’ = ‘No Collisions’
Image for post
That’s it! Now you should have a working 2 way teleport system. Pretty cool huh?