Game Maker – Dynamic Teleport

When searching for a teleport system in Game Maker, I often find the following  suggestion. When object A collides with object B at position (x,y) change object A’s position to (x_new,y_new). This works perfectly if you require a fixed position teleport system.

Though, what if you wanted (given any character position) to be able to teleport to a location that is not pre-defined. A dynamic teleport. What do you do? I asked myself this, and here’s a simple solution that I used for my puzzle platformer Multi.


First lets define a few terms and variables:

  • Ideal Teleport – A teleport  which results in the character being where you most want in a regular scenario.
  • Teleport – A boolean variable that determines whether the character can teleport or not. It is reset with the use of an alarm.
  • Teledist – A fixed integer that determines the position change of the ideal teleport. I used the value 96 pixels.
  • Par_solid – The fundamental solid object of my game (I did not use Game Makers solid variable, this article explain why.

It also helps to know  the basics of Game Maker Language’s (GML), and how one of its functions place_meeting works. If not I suggest you check out this great post in the Game Maker forums by Torigara.

The System

It can be broken into two steps:

  1. An Ideal Teleport Check.
  2. (Optional) A Backward Search.

Step 1

Let us consider the situation below. Our character needs to teleport past the solid blue block to reach the yellow square.


The player first presses a button that corresponds to a pre-defined game maker event, such as the left arrow to teleport left. At this point we must check whether the ideal teleport is possible. The red line denotes the approximate distance of the ideal teleport.

Using the place_meeting function  we essentially check to see if we can ‘fit’ in the space. In the above scenerio case we can, so an ideal teleport is possible. We then make the necessary position changes, leaving our character in the position denoted by the green square.

Heres the code which does that:

In the above code the x position of the character was changed. If you wish to handle different directions such as up and down, you will need to appropriately change the x and y coordinates of your characters position.

The lower part of the code sets up a timer for alarm zero which is an event that resets the teleport variable to 1.

Step 2

This is optional, but I highly recommend it for it’s added functionality.

In the following situation the player is unable to perform the ideal teleport but yet there is ample place to teleport closer to the solid blue block. A backward search is what we need.


A backward search involves using the place_meeting function to ‘check backwards’ in intervals from the ideal teleport location until the place_meeting function returns false. In simpler terms, we keep searching backwards till we find a position we can fit into. The place_meeting check interval I used is  one pixel at a time, but this can be easily changed.

When we combine step one and two we arrive at the full system. Here is the code:

A feature worth mentioning is the ability to handle teleporting between tight spaces. I found this provided good design opportunities.


Now if this method doesn’t work for you, I hope it at least puts you on the right track to implementing what it was that you wanted. Always adapt as necessary to your own project. Good luck!

To see a working implementation of this teleport system, checkout my game Multi!

Leave a Reply

Your email address will not be published.

two + thirteen =

This site uses Akismet to reduce spam. Learn how your comment data is processed.