- Home /
How to make a smart warp system?
Hello everybody. A few months ago I developed a 2D RPG with tiled maps, in that classic Pokémon-style, and I had to create a warp system so the player could go from one map to the other, like in Pokémon, when the screen fades out and the player appears on the other area. And for that, I used Box Collider 2D as triggers, both to warp the player to the next map, and to instantiate the new map. But I had like 10 maps per scene, so each scene had like 30 or more triggers, and I had to assign where the player would appear and where the map would appear in each script manually, and it took a lot of effort, and dozens of hours of work. I'd like to know if anyone has some suggestions of a non "go horse" way of doing, like the one I did. Thank you.
Answer by AlwaysSunny · Feb 27, 2017 at 03:36 PM
Yowza, that sounds like a lot of work!
Depending on how you've got your scenes and logic set up, there may be superior ways. As with all things programming, different situations call for different solutions. YMMV.
It sounds like a job for a map editor. Imo, this is a scary term that drives newcomers away. A map editor is just a suite of tools that help you work smarter, and you can build them one at a time for specific tasks like this.
Your tool could've offered you a button that somehow marks the warp tiles - departure and arrival - with metadata that makes them "know" each other. This could've been automated to the degree that you could've set up each warp with a few clicks.
How to best add that markup - e.g. automatically creating BoxCollider helper objects and automatically cataloging them for easy inspection - will vary from case to case.
Creating tools for yourself is often a good way to think about problems: Not just how to solve XYZ problem, but how to solve it a hundred times down the road very efficiently.
Thanks for you answer! The map editor I use is Tiled, and I don't think it has something like a s$$anonymous$$dy warp system, so maybe I need to find another tile editor, one that fits my needs better. Thank you again.
I don't know the "classic Pokémon-style" as i never played such games ^^. However teleporting to a new map / area has been implemented in many games. For example even Halflife needed some way to match the newly loaded map to the old one and it does that "seamless". Halflife usually uses a point entity called "info_landmark". Those have a unique name. The trigger that actually changes the level will use one of the landmarks for the transition. There has to be a landmark with the same name in both levels.
When the transition happens the game will calculate all positions of entities that should be taken over relative to the landmark of the old level. When the new scene is loaded it does the reverse. The easiest way would be to temporarily add all those objects as childs to the old landmark and mark the landmark with DontDestroyOnLoad. When the new scene is loaded you would simply move the old landmark at the same position (and maybe even orientation) of the landmark in the new level. Unparent all objects and destroy the old landmark.
One level can have several landmarks for different transitions, just ensure that the names / IDs / whatever are unique and always have a matching partner in the other scene. Setting up those landmarks should be fairly easy. Though a little editor tool never hurts ^^.
I think I understand what you're suggesting. It's a very advanced way (at least to a peasant like me). Thank you man :)
Answer by Bluestone19 · Feb 28, 2017 at 04:07 AM
Just some basic suggestions: If you haven't already, make a warp zone prefab, to cut down on some time. If the maps are in the same scene, you could make a "link warp zone" prefab consisting of two warp zones that warp to each other, possibly changing the destination slightly if necessary to facilitate player direction. Make use of public variables to streamline fine-tuning if necessary.
I think the way you're suggesting is a smart version of what I did : I used a script with public float variables for the x and y coordinates, so I could assign where the player would warp to. Bu I had to do manually it for every single warp trigger in each scene, and in the end my hierarchy was polluted with more than 30 game objects just for the triggers, and in the end of the third month of development, my brain was melting down due to the confusion I created on the hierarchy. Thanks for the suggestion dude :).