Forum rules - please read before posting.

Need help with a sliding box puzzle

Hello there!

I am in the process of creating a 2D mini game in which players will push boxes around a room in order to allow a character to escape. The mechanics are similar to a sliding box game, except that the final position of the boxes won't matter. Here is what I want it to do:

I'm having a hard time getting my head around how to do this! I can successfully get my action list to evaluate a box's adjacent positions and move to an empty slot the first time it's clicked, but then it gets all wonky if/when I click the same box again later. I've tried a few iterations of this, but now I'm thinking I'll start over by making use of two types of variables:

  • Boolean - to determine whether a slot is open/empty or not
  • PopUp - one for row value and one for column value

Am I on the right track at all there?? The confusing part (I believe?!) is how to keep having the action list check a box's "updated" position when it's clicked more than once, like when an adjacent spot opens up again.

Can someone explain this to me as though I'm a person with NO experience in scripting (because I am)?? Please use small words :blush: so I can hear it over the static this is creating in my brain!

Thanks-

Ann
Unity 2023.2.08.3202.5344
AC V1.80.2

Comments

  • If you have very specific behaviour in mind, it might be best to rely on a dedicated asset built with this kind of gameplay in mind.

    That said, an approximation of this should be possible in AC. There are a couple of ways to go about it: essentially boiled down to how important the "dragging" input is.

    If you want to be able to "click, hold and drag" a box to its next position, I'd say look into the Arranging Puzzle template over on the Downloads page. Its gameplay isn't specifically for sliding box puzzles, but it is fairly flexible and could be tweaked if necessary.

    Study the included Jigsaw puzzle first, but essentially you'd have a Slot for each spot a Box can be placed in, and each Box would be a Puzzle piece. The template prevents two pieces from occupying the same slot - so I think the main obstacle you'd end up facing would be to limit the dragging of a Puzzle piece to the confines of the space it can move. This'd be a case of attaching a custom script to restrict movement of a selected piece - possible, but tricky.

    The other approach - though one that would limit you to automatic movement, i.e. clicking a Box causes it to move to the empty space automatically - would be to rely purely on ActionLists, variables and parameters, as you have been.

    The tricky part is to work out if a Box can be moved, given the positions of itself, and the empty space. I think this can be done by way of Vector3 variables - if each Grid space is 1x1 units, for example, a Box can only be moved if the distance between itself and the empty space is exactly 1.

    Essentially, you'd record the position of the empty space as a Vector3 variable, subtract the chosen Box's position from this, and check its magnitude. If it's a match, you can use the Object: Transform Action to move it to the empty space, before updating the "empty space" variable with the Box's previous position.

    I've had a look a the ActionList workflow, and there are a couple of tweaks to make to the Variable/Parameter Actions in order to make this work. I'll look into these as part of the upcoming v1.80.4 update.

  • Thank you so much for this. I was aiming to do the latter, particularly since I don't know how to do any custom coding. I had it kind of working yesterday... but since I [foolishly] started with a 6x6 grid, the complete action list has just over 700 actions in it. 😖 I'm sure I'm over-complicating it with one of these lists for each position on the grid:

    Is this total rubbish??

  • You don't need anything so complicated - avoid manually entering in position values, and the technique should allow it to be the same number of Actions regardless of how large the grid is.

    Let's start over - a 6x6 grid should be OK, but you might want to go a bit smaller to start off with.

    The changes I mentioned making above are included in v1.80.4 - you'll need to grab it first.

    Then, follow these steps:

    1. Create a pair of Global Vector3 variables named Empty position and Calculation - the first will store the position of the empty space, and the second will be used for handling some calcuations when a cube is clicked.
    2. Set the default value of Empty Position to the centre of the empty spot.
    3. Take your cube with Hotspot, and attach the Moveable and Constant ID components. Make sure that the pivot point of the cube is at its centre.
    4. Set the Hotspot's Interaction source to Asset File. Create a new Use interaction and have it run a new ActionList asset file.
    5. In this asset file, define 3 parameters - a GameObject named Cube, and two Vector3s named Cube position and Empty position.
    6. Return to the Cube Hotspot, and assign the new Hotspot parameter field as itself. You can now duplicate/prefab this cube to make as many copies as you like.
    7. Inside the ActionList, add the following Actions (comments can be ignored):

    I've assumed here that the space between two points on the grid (not-diagonal) is 1 - you'll need to adjust the two Variable: Check Actions to surround your own value if this is different.

  • OOOOOH!! Thank you so much! I will work on implementing this immediately!

    Cheers!🍻

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.