Forum rules - please read before posting.

Fit puzzle pieces together?

edited October 2014 in Technical Q&A

So I have a classic puzzle game er... puzzle in my game where you basically have to fit a number of pieces together (like pieces of a treasure map let's say)

These pieces you collect from around the game and carry them in your inventory and the idea is that when you interact with a special object/hotspot in the game you can drag and drop these pieces from your inventory and fit them together on this hotspot (so imagine a special table or something)

Does anyone have any pointers about how to do this using AC? Or am I better off bypassing AC in this case? Even if bypassing it is the way to go I kinda need to mix and match as I need to be able to drag and drop these pieces from my inventory in this special "puzzle game" screen (so I need the inventory at least to be active here)

At the moment I am using a camera switch to switch to this table and I also have a fake UI with a single "Go Back" button (which takes me back to the main game. So that works quite well (apart from the fact that I get the Use icon when I hover on the Go Back button - makes sense as I used a hotspot to implement that - any way to suppress the icon in this case?)

So zooming in and out of the table screen works great, now I just need to figure out how I can drop these pieces from my inventory and have the ability to drag them around and rotate them so I can implement this puzzle logic.

Any pointers much appreciated!


  • I have a similar approach to a 'look at stuff' table. Not a puzzle in itself but similar in that I put a 'go back' button in.

    following from some advice from Chris I have eliminated the 'use' icons by setting the icon to be simply the pointer. (I made a new icon in the "Interaction Icons" under the Cursor Manager and simply put the pointer icon in there).

    My question as to how to get this interaction sorted was asked here: 

    As for your puzzle I have no specific advice other than to suggest instead of utilising the inventory at the 'solve time' you might use your table space as a 'drop off point' where the pieces appear once you have collected them. Given the new physics puzzle system I expect AC should be able to control the lot very well.
  • This may be possible with a bit of tinkering.  Try giving this a go (rough steps):
    • Make the board/table where the puzzle takes place a Hotspot, that has an Inventory interaction for each puzzle piece.  That way, you can drag and drop your Inventory items onto it, and have a reaction.
    • Each time you use an item on the board, remove it from your inventory, and make visible a scene-based representation of it (e.g. a "map piece" mesh).
    • Convert these scene objects to Draggable objects (add a Draggable into the scene, attach the mesh as a child), and use the Draggable script inspector to change the "Drag mode" to Move Along Plane.  Then assign a plane for 2D movement, and you'll be able to drag the piece around the table (even if the camera is viewing the table at an angle)
    • Use Triggers for each grid slot that pieces can be placed, which are set to detect only the one object that should be in that place.  Once a piece is in the correct place, you can use the Object: Send message Action to disable it from further movement.
    Hope that made sense - it should work in principle!  If you have more questions, better to post some screenshots for us to work with.
  • Hi, I had started on this already before I saw your response and I am glad to see that up to step 2 I actually did exactly the same stuff.

    I didn't know about Draggable so I didn't use it, but I am not sure it would work in my case anyway as I need to be able to both drag *and* rotate these pieces. So I am actually attaching a custom script to these objects and I also have a small manager that deals with the logic for this "minigame" (handles input, tells the rest of the game when the puzzle has been completed, handles snapping to anchor points etc.)

    This seems to work more or less in principle, one problem I am having though is that there's a clash between the AC hotspot that handles placing these pieces from the inventory into the board and the colliders that I need to add to these pieces to detect when they are being clicked on and selected...

    I think the issue is that the Make Visible message only affects the renderer for the object so the collider is always active and obstructs the hotspot (I don't mind it doing that once the piece is visible actually, it's only before the pieces are actually placed on the board that this causes a problem)

    So I think I may need to write a custom action that enables not just the renderer but also the collider of a gameobject.

    I tried using the Custom Message and writing a function in my PuzzlePiece script that does that (basically just does enabled = true on the SpriteRenderer and the Polygon2DCollider), but this throws an error when the custom message is fired saying "there is no recipient for this message" even though I have set the recipient object for this action properly in the inspector.

    So not quite sure why this is happening...

    Alternatively I may look into placing these pieces in a layer that won't clash with the hotspot...but I think unless you put them in Ignore Raycast they will always clash and if I put them in Ignore Raycast then I can't do picking on them anymore...
  • Forgot to say: Xidore the trick with adding an additional interaction icon and using the default cursor worked perfectly btw, thanks!
  • Aha! Success.

    I thought I might try using the Teleport action instead. So I am now hiding my pieces away just outside of view, then when one is placed on the board from the inventory I teleport the corresponding piece where it needs to go (using a preconfigured marker - I'd love to use the position of the actual mouse release at some point, but I can look at that later, this works quite well for now)

    Oh btw, in case anyone else needs to do something similar, I just realised I missed something crucial from my previous description:

    The "target" marker where the piece needs to go once it's teleported, is set a few units in negative z so that it is on top of the hotspot that corresponds to the board (I am using an orthographic camera so this is fine). This way once the piece appears on the board it will "hide" the board hotspot in the area where the piece's collider is active, so any picking/raycasting that you do will be captured correctly by your custom object.

    Bit hacky I guess but works well and I couldn't think of a better way to do this...
  • If it works, it works!  Just in case you didn't know, though: you can use the Object: Send message Action to "turn off" Hotpots and the like.  It'll move them onto the Ignore raycast layer, disabling them until you turn them back on.
  • Yup, I saw that trick in your early tutorials and have been using it extensively!
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.