Collision Detection of the Player, by Layers

Hello! I've been encountering an issue in my project since at least November 2017, and I think I've finally come up with a novel solution! First, however, I must explain the problem. (You could read it in the link, of course, but I'll summarize it here.)

My project uses a Layer System, Collision Map, and Free Movement, all through scripts, to obtain a mapmaking system similar to parallax, free from the grid (mostly). I added more realistic aspects to my maps, including making the walls thinner than one tile so the player may walk behind them. The obvious consequence of all of the walls being a single image, of course, is that there's no way for the game to differentiate if you're in front of, or behind them. Whatever z-level you choose for that layer decides how it renders in comparison to you, and that's that.

I had an epiphany today, though. I can split the 'walls' layer into multiple images- one for each horizontal region of wall. Vertical segments cannot be walked behind (You can walk under them, in the case of doorways, but the player is always under these.), so there's no need for those. I thought,"What if the bottom pixel of the wall is on another layer, so the player cannot touch any of the wall layers from their front side? After arranging this, I could request a script that changes the player-character's Z-Level on contact with the wall layer, so they'll appear underneath of it!"

Here's a drawing to illustrate the concept.

Concept Art 06.png


The green boxes represent the player-character's hitbox, which can be customized with the Free Movement script linked above. Notice that the player-character in front's hitbox is in contact with the wall, but only the black line. This black line would be part of the floor layer, but still impassible, giving a buffer between the wall layer, and the player-character's hitbox.

Now that I've described this, the script I'm requesting needs to:
-Detect if the player-character, or an event's hitbox is making contact with a wall layer (The layer covers the entire map, so the script must be able to ignore empty space.).
-Change the player-character/event's Z-Level quickly enough that it won't disturb players.
-Events set to "Above Characters" would not be checked.

Any help, as always, is appreciated. I'm so very close to releasing my demo, so I just need to finish cleaning things like this up.
I made a "Map Objects" script some time ago which could solve your Z level issue in a way, but it requires you to place your walls as "objects" on the map, and not as a single image layer. If I read it right, you already wanted to separate your wall layers, so I guess, this won't be a problem, right?

It's basically a script that lets you place images on your map anywhere and in any amount with a good few extras (animated objects, image property settings, etc).
The layering is working "out-of-the-box" if you place your images correctly, since it uses the default Y based positioning, so long as the wall images and the player (and other characters, of course) is on the same Z level.

Well, actually, it's a separate map editor, not really a traditional "script", since you do the image placement in an editor, so you will see where it goes and how it looks like during the game in real time. But given how many custom scripts you use which change the map scene, it's safe to assume that it won't work without some patches, since my script uses the default map scene as well (a stripped map scene - removed everything which is not needed for the map editor and killed the default map scrolling, which is why it may not work without compatibility patches).

But if you want, and if you send me a demo project with all these scripts you are using and at least 1 map fully setup with events, and all that, I may be able to make it work in your project.

The script as it is, won't let you change these map images during the game, it is strictly a mapping tool, not a new game feature, but adding in some switch/variable conditions shouldn't take long, so I can drop in those features too if needed.
That sounds like a very good script! Since it would be such a large change, could you pm me a copy of it for me to look at first? Your work is always high-quality, so it's not that; I just want to make sure it's something I'm interested in before you put too much work into making my project fit.
I didn't make any documentation for that script, and it could be a bit hard to use without the instructions about some settings and about the image/folder setups.

I will write those instructions tomorrow and post that script with a demo on the forum. It was a good while ago since I posted a new script topic anyway. 😀
Fair enough! I'll gladly wait until then!

Oh, and while I was waiting, I remembered this old script I found last year. It can detect collision down to the pixel between a picture and a sprite, and it will work for me if 'pictures' can be expanded to include layer images, and the player's collisionbox (defined by the Free Movement script) is used instead of the player's sprite. This will have to be expanded to work for events as well, but on the bright side, I've tested it already, and it's compatible with my project!

Sixth's script might work, but I like to keep my options open. 🙂
Sixth posted this:
https://forums.rpgmakerweb.com/index.php?threads/map-objects-v1-0-06-06-2018.96175/

I haven't tested it thoroughly yet, but it seems to be what I need! I recommend anyone else dealing with this issue to check it out!
If your query is fully resolved, please Report your opening post and ask for the thread to be closed.
Thanks.
It's not certain that it's resolved yet. I still have a lot of work and testing to do to make sure this solution covers the whole problem. If it's really that big of a deal, I suppose I could just PM Sixth if I have an issue, but I prefer not doing that unless I have to.

When I'm sure of its efficacy, I'll have the thread closed. Don't worry.

Edit: I don't want to doublepost, so I'll write this here.

@Sixth , I've been testing the script in the demo you provided so far, and there's been few issues. However, I installed it in my project, and as we expected earlier, the other scripts do not agree.

I have to say, after almost three years of RPG Maker, this is the most number of individual scripts I've ever seen referenced in an error!

Game_Bug_031.png


This error only occurred after removing a couple more scripts that caused it to crash. I've been inserting some of these scripts into your demo, to see what makes it break, but there's a lot to go through still. While I work on this, did you want a copy of my project to look at, still? I can't tell what the issue is here, but maybe you can.
Bump. @Sixth , did you see my edit?
Ohh, nope, sorry, didn't check the topic after your last post.
I don't remember seeing any alerts for that @ mention either. Weird. o.o

Anyway...
If you send me a demo, I will take a look at it.
It seems like another script is overwriting the method I created that instance variable in, which is why it's nil in your project.
Alright. I'll clean up the project some and pm you the demo- might take a bit. I'd prefer not to have a public download, yet.

Perhaps @s in an edit don't send an alert? I can't see why else that would happen.

Original thread: https://forums.rpgmakerweb.com/threads/collision-detection-of-the-player-by-layers.96101/