Ultra-easy creation of Push-Pull object

A standard problem with creating puzzles which require the player to push an object around is that the player may end up pushing it into a position where it is then stuck.  Normally the player must then either leave the map or throw a switch to reset everything.  This can be frustrating, particularly if several objects have been successfully moved, as the player must now start again from scratch.


This is one of the easiest things to prevent, by creating an object which can be pulled if (and only if) it cannot move forward.  It just requires a couple of script calls.


In the example in the screen shot I have used a boulder and the appropriate SE.  You, of course, can use whatever you like.  As the script calls are too long to show clearly in a screen shot, I will go over them below.


Push_Pull%20event_zpsebnpouco.png



The script call in the conditional branch (tab 4 of the Conditional Branch menu) is this:


e = $game_map.events[@event_id]; e.passable?(e.x, e.y, $game_player.direction)


This is checking if the tile ahead of the object is passable.  It works out what “tile ahead” might be by looking at the direction the player is facing.


If it is, then the object moves.  If it is not passable, the command goes to the ‘Else’ branch.  The script call there is:


$game_player.followers.reverse_each {|actor| actor.move_backward }


Note that this script call is part of a Set Move Route command, for the Player.  It takes into account if you have chosen to show the Followers as well as the Player. With this script call, the player and all followers move backwards and the object follows with its own Set Move Route command.


Done.


Variation


Suppose, though, you want the object to be pushed or pulled at the player's choice?  For this example I have chosen to set it up so that if the player presses the 'Shift' key while interacting with the boulder, they will 'pull' it, otherwise it will be 'pushed'.


Push-Pull%20Event%2002_zpsntnerjyw.png



The condition is that the shift button is being pressed.  If it is, the Set Move Route for the player begins with the same script call as the first example, that is:


e = $game_map.events[@event_id]; e.passable?(e.x, e.y, $game_player.direction)


The player (plus followers) move backwards, and the object follows them with its own Set Move Route.


If it is not being pressed, the 'Else' condition is just the normal move command for the object.


In both these examples, if you have Followers turned off, then you do not need the script call.  You simply set it so that the player moves backwards.
This looks interesting, but i somehow have the feeling this could be exploited in puzzles.


But i realy like the follower stuff.


But if you dont mind here is the Idea i had some time ago.


I placed region 2 around the map boarders, and as soon the rock gets there and the player moves away, the rock rolls back one tile.

Spoiler
rock-1.PNGrock-2.PNG
@Bex Yes, it is precisely with puzzles of varying complexity in mind that I did this.


Thanks for your alternative suggestion, but my objective was to make the creation of these objects as simple and straightforward as possible.  I did not want to use regions or other complicating factors - particularly regions such as region 2 which is used as default in a number of scripts affecting regions.


I wonder if you would mind putting your images inside spoilers, as they are not directly relevant to my tutorial, and I would rather that other Members didn't start using this thread to make comments/ask queries about something else.
No problem, and yes my sugestion would still need the buton for resseting.


Thats why i like your aproach. Thanks for the Tutorial.
I should pin this somewhere 😀

Original thread: https://forums.rpgmakerweb.com/threads/ultra-easy-creation-of-push-pull-object.68430/