How do I teleport from a layout to another and save the last position + direction?

0 favourites
  • 8 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Hello there.

    Ok so, here's my usual premise:

    1) If there is one thing I'm really bad at is programming, so I'm sorry for asking weird questions.

    2) Also, I've recently decided to fully work on Construct 3, and now that I've more time I want to get more experience. This is also why I want to give my theories about how *I*, a very unexperienced programmer, would have solved it.

    3) Yes, I've followed the first tutorials and I've also managed to start making a 4 directional game with sprites and all.

    4) I know what a global variable is. I'm saying this for the next point.

    5) Before to open this topic, I've actually searched on Internet and in the search section. The question is pretty common and I've found many answers, but I must say, sometimes I could understand only a half of it or are outdated. Many of these answers talk about using global variables to store the the coordinates.

    -----

    The title says it all. I have multiple rooms of which the character has to move onto. The player can go back if they want to, so it's important to keep the last position in that layout, and possibly the last direction of the character (if I'm moving down from layout 2 to layout 1, the character should face down in layout 1). For many it's pretty easy. For me, I'm just at level 1.

    ---- THEORY

    I'm a Halo fan, and since Halo 3 there is this mode called Forge, which allows you to make your own Halo maps. In forge you have the access to make teleports. There are three type of teleports:

    1) Only sender

    2) Only receiver

    3) Bidirectional (both sender and receiver)

    For example, with a sender and a receiver, if the player has a collision with the sender, they will reach the receiver, from point A to point B. The player cannot go back, tough.

    With two bidirectional teleporters, you can go to point A to B and vice versa.

    Another important aspect of the teleports is to give a "channel" frequence.

    If the sender is set to "alpha" and the receiver to "beta", basically you cannot teleport to the receiver, because they don't have the same channel.

    If they have both the channel "alpha", however, you can move to the receiver.

    My point is more or less the same. What I thought is pretty much this:

    1) Make bidirectional teleport (or in this case an invisible wall to collide with the character)

    2) In the bidirectional teleport, introduce a variable called "channel".

    3) If the teleport1 from layout1 has channel = 1, and teleport2 from layout2 has channel = 1, and the player has a collision with teleport1, the player moves to teleport2. And vice versa.

    Does it make sense?

    I think there are two problems, however: What happens if the player teleports exactly to the point where the other teleport is? Wouldn't the character be stucked between the two teleports?

    And let's not forget of the direction.

    About these two factors, I'm not aware exactly of what to do. Plus the fact I'm now sure how to use the global variable to save the player's coordinates.

    This is pretty much what I would have done, logic-wise. But I'm a beginner, so I don't know, I guess there are better alternatives.

    The idea of using "go to next/previous layout" seems risky to me, and I actually want to be free to eventually change the channel number and consequently the point between these two layouts.

    Also, I'm not sure of using "Go to layout" because I should do the same event over and over for each teleport, it doesn't sound efficient(?). You tell me what's best, I'm all ears.

    Thank you for reading.

  • Laura_D made some videos on Twitch and on Youtube for her Digimals project, that has moving from a layout to another with invisible teleporters.

    I'm afraid I can't tell you exactly in what video this exists, but this can be found in this playlist : youtube.com/watch

  • Also, check out this demo - is this what you are after?

    howtoconstructdemos.com/a-system-of-doors-portals-to-travel-between-layouts

  • This is the text version of what Kyatric is talking about!

    Probably needs a bit of polish, and could be tweaked but it works for me in my game! Hopefully gives you an idea :)

  • Hi there. Sorry for the late response.

    Thank you all for your support, you're incredible!

    Yes, dop2000, the link you sent is what I'm referring to.

    I've played the demo and watched the event section, and it's exactly what I want to replicate in my game. I had to change some things for the movement due to the issue with the direction. Other than that, it's 100% working.

    Also thank you for all for the links, I'll give a look now. Now I want to make a simple fade in/out transition.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi there. Sorry for the late response.

    Thank you all for your support, you're incredible!

    Yes, dop2000, the link you sent is what I'm referring to.

    I've played the demo and watched the event section, and it's exactly what I want to replicate in my game. I had to change some things for the movement due to the issue with the direction. Other than that, it's 100% working.

    Also thank you for all for the links, I'll give a look now. Now I want to make a simple fade in/out transition.

    I'm sorry for reopening the subject. I seem to have an issue with the Z order. I'm not sure yet. So I've followed dop2000's guide and the teleport works fine.

    Now I've noticed that, if I use two teleports, one in layout A and one in Layout B, and frequently change layout, I see the player decreasing its Z Index of 2 positions until a certain number. So I see the player going behind the background or some objects.

    I've also noticed that, when the player spawns in another layout, there are actually two player sprites. The original one, which you can see, and another one, which is apparently invisible.

    EDIT: Nevermind, fixed in the same way I fixed last time.

    Basically, the player was set to global.

    Turn it off if you have it, else you get copies of the player.

  • In my demo I only change player's position, this should not affect z-ordering in any way.

    Are you spawning a new player on start of each layout? Check that your player sprite is not set as Global. If this doesn't help, there must be some other mistake in your code, please share your project file.

  • In my demo I only change player's position, this should not affect z-ordering in any way.

    Are you spawning a new player on start of each layout? Check that your player sprite is not set as Global. If this doesn't help, there must be some other mistake in your code, please share your project file.

    Awkward, about 1 hour after I sent my message I updated it just by saying that I did indeed solved it again in the same way I solved the other issue - and yes, it's just as you said, the player was set to global. Not sure if you can see the edited message.

    Again, thank you very much for your help! I guess I cleaned up a bit some events and I believe it's going perfectly now.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)