Open World Platformer- Teleporting the Character where they need to be

Hey guys! So I’m making an open world platformer, inspired by the mechanics of Hollow Knight or Ori and the Blind Forest. My general idea, is that you can backtrack if you want, to get all the items and secrets in the game. Talk to NPCs at the beginning of the game, go forward to the end, ect ect.

I have no problem teleporting a character from one scene to another, but. I am not sure how to make them teleport to different locations in that scene. For example, if someone is entering from the left to a new scene, that the player sprite appears on the left side of the new screen. Or, if the character is entering from the right side of the scene, that the Player sprite now appears on the right.

This has been a thing that’s confused me the most so far! So thank you in advance for any help you can give me!

To teleport a sprite, simply change it’s x and y positions. You can use a global variable to tell the scene where the player comes from, and teleport it at the beginning of the scene to the good place

1 Like

As Arthuro says Global Variables. There are a few different ways. I think the way I’d do that is to have a trigger object on the far left and far right of the screens. So when the character is in collision with the trigger object it changes the Global Variable. This object could also serve as a spawn point object so that the player will spawn from these objects on the scene. (you can hide them so they aren’t visible)

Event 1
Condition: “Your Player Object” is in collision with “Left Object”
Action: Change the global variable set to 1

Event 2
Condition: “Your Player Object” is in collision with “Right Object”
Action: Change the global variable set to 2

Then in the new scene… You could spawn the player at the right or left objects in that scene.

Condition: Global Variable = 1 (or 2)
Action: Change position of “Your Player Object” to “Left Object” (or the “Right Object” depending on if the variable is 1 or 2)

Sweet, the Global Variables DEFINITELY make a huge difference! I did as you suggested, but the character stays stuck in that position. What would you suggest to give the player movement?

Thank you very much you guys!

Also, I am unsure how to structure something specifically as a spawn point object. Any suggestions you could give would be extremely helpful, thank you!

Try doing Trigger Once as a second condition, otherwise i think the character will stay stuck there.

As far as the spawn object… It’s up to you if you’d like to use one. You could just use the x/y position like you’ve already done if you prefer. But if you decided to use spawn/exit objects, they are just normal sprite objects. You place them on your map in your desired locations so that through the events you can then tell the player to appear at the position where that specific sprite object is.

Thanks a bunch, that helped fix the problem for sure! I tried the x/y option, but it definitely makes the screen ‘glitch’ for a moment. I’m trying to figure out the action required to have the player spawn at those locations, though I am struggling with that a little bit as well. I’ll look through the events and find the specific event soon, I’m sure!

Thank you for all the help!

EDIT: Yes, I can’t seem to figure out the spawning option through my events tab, no matter where I look. I’m afraid I want to ask the exact way you might do it. In the mean time I’m going to keep trying to figure it out myself, thank you!

I am working on a platformer with similar mechanics (large map broken into smaller scenes). What I did was make my character a global object (so I don’t have to make one in each scene), then use “create object” action at the beginning of each scene, passing the desired location using global variables from the exit point of the previous scene.

The way with spawn objects…

  1. Create a new object, select Sprite object and name it (for example) “LeftSpawn”. Use Piskel to quickly bucket fill in that object with any color you like (so it will now look like a colored square).
  2. Drag that LeftSpawn object into your game map and place it at the position where you want the player to spawn.
  3. Now you can either use the

Action: Create (Your Player Object) at LeftSpawn.X(), LeftSpawn.Y()

or if you already have your player object dragged into the map, you can just use

Action: Change the position of (Your Player Object) to LeftSpawn.X(), LeftSpawn.Y()

That makes so much sense!! I’ve been using everyones suggestions here and trying them all out, but I suspect doing it exactly like this might cut out my screen twitch I’ve been having. I’ll test it out, and get back to you on it!

Okay, now that I understand using spawn points, I am having no issues except one.

The character is definitely appearing where they need to be without issue, but there is still a visual glitch that happens for a split second, jumping from screen to screen. I’m wondering if my camera has something to do with it. If anyone had this issue themselves, please let me know!

Here is the code I’ve made:

I suspect the lag is just due to the way GDevelop works. GDevelop is interpreted, not compiled, which makes it a bit slower. [edit]correction, in 1998 javascript was interpreted, but it’s obviously advanced quite a ways since then :slight_smile:

What you might try is some sort of transition between scenes. For instance, a fade out at the end of one scene and fade in at start of next scene.

A lengthier way to fix it is to make sure that the spot you leave one scene and the place you enter the next look the same.

Actually- I was doing a bunch of research both in the forums, and on youtube (And I opened up Hollow Knight to see how HK does it) and I learned how to make transitions between scenes. Now it looks beautiful and seamless. Thank you guys so much for all the help, everything is running smoothly now!

1 Like

Just so you know: your problem here was dismissing the order of events which is important. You first centered the camera on the player and then moved it, so the camera stayed for one frame at the old position. You should have put the center camera after repositioning the character.

That is wrong at many levels. First of all, that is not lag but a bug. Secondly, having a slower game cannot cause a camera glitch, only frame drops. Finally JavaScript is not interpreted but compiled just-in-time. That basically means that it gets compiled on the end user machine.

1 Like