Collision Check Ledges

Hi there,


I am fairly new to all this, but am not that new to programming. Just a heads up that I am ok with script solutions.

I believe this is a common problem and I have been searching a lot, but did not find anything concrete.
I attached an image. In there you should see a red line. I want the player to not move past the red line from left or right. However the tiles next to the line, I still want to be passable.


I tried to solve this by putting an event on the grass tiles, saying that when the player touches the event from the left, turn THROUGH off. Else turn THROUGH on. (Indeed this is not the complete solution but I am testing for now.)

What happens is that I indeed can't pass the line left to right, but the moment I enter the grass tile from another angle, I can pass over the line from left to right again. As if the event can't be triggered again or the Through flag cant be turned off again.


If : Player is facing Right
Set Movement Route : This Event
: Through Off
Else
Set Movement Route : This Event
: Through On
End


Also my Option for through is checked off in this case.
Is it something I did? Or am I missing some wait or closing commands? or just improper handling?


Capture.PNG
The easiest solution would be to put a bush/tree/other blocking object there.  If you want to keep with the events you would need 2 events, one for the grass tile to prevent movement from the ledge and another on the ledge to prevent movement from the grass.
The easiest solution would be to put a bush/tree/other blocking object there.  If you want to keep with the events you would need 2 events, one for the grass tile to prevent movement from the ledge and another on the ledge to prevent movement from the grass.





Hi, thanks for the reply!
Right as I fixed the issue I read your answer.
It's as you say I have to use 2 events per ledge. Only I did not have succes with the Through flag at all. It kept being persistent in the ON state after I entered the tile. It's not that strange it reacted like that though.

I read through the .js files and found that Input.dir4 returns 0,2,4,6,8 according to the numpad equivalent directional buttons. (0 being no input)


So to fix the problem I made the following code for the tile on the ledge:


Loop
If : Script : Input.dir4 != 6 || Input.dir4 != 8 || Input.dir4 != 0
Break Loop
End
Repeat Above


Here i continuously do nothing unill I press a direction other than either right, up or nothing (0) on the event tile.


There is one drawback on this method though... While doing nothing, you can ABSOLUTELY do nothing. That means you can't press anything till you press left or down. Not even open the menu.

I did find a way to include the escape/menu button in this code, but it would cancel the loop and so ruin the point of this.



There is a way however to still add functionality back to the escape button while standing in the event tile though:



Loop
If : Script : Input.dir4 != 6 || Input.dir4 != 8 || Input.dir4 != 0
Break Loop
End
If : Script : Input.isPressed('escape')
Set Movement Route : Player (Wait)
: Script: SceneManager.push(Scene_Menu); Window_MenuCommand.initCommandPosition();
End
Repeat Above


Note: This only applies to keyboard controls, I think Controllers will still have issues and needs to be added the same way as well.


Note: I am in this case working in a corner (against a wall). If I did not check for up (8), it would cancel the loop while I am still in the same tile. It would also do this if I walked up onto the tile. This would break the functionality.


That is why I had to check for up (8) as well.  In case you are not against another wall, the check for up (8) can be removed.

Note: Another con is the small input lag you get in the event tiles. Very small, but it is there. If this is bothersome to you, indeed just put a plant to obstruct acces to the edges.


This is my solution, if someone has a simpler solution, please do share. For now, I am content with the solution I found and hope this also helps others.
I'm aware this is an ancient issue, but I happened upon it and figured I would state what I did. In your tilesets (E for example) you can create your own set of tiles.


I have attached the files. In the top left you'll notice a series of thin lines. Those are based on some RTP stuff. I have the directional set for each one based on shape and location. If I have any ledges that I don't want people to cross over to the floor below then I use those. You don't actually NEED the graphic. You could finish your entire game, and then at the end just remove the graphic from the tilesheet and it will have the same effect, but with no graphic.


Hope this helps (If you didn't fix it another way).


~Serv

ARK Storage Room, Kitchen E.png
Servidion, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.


Furthermore, a quick check (hover your mouse over the profile picture) would have told you that the OP has not visited the site since June last year, so is most unlikely to see your suggestion.

Original thread: https://forums.rpgmakerweb.com/threads/collision-check-ledges.58949/