Forum rules - please read before posting.

Moveable Objects that block the players path?

Figured this would be a common problem but I couldn't find a single other person asking about it! So I must be missing something simple.

So, I want to do a classic "push block" puzzle. Where there are several blocks, the player can push around to clear the path. But I can't figure out a way to make the blocks block the players path. I saw I can make different nav meshes, but doing different navmeshes for every single combination of possible block locations sounds practically impossible. Surely there is a way to make a moveable objects obstruct the player?

Comments

  • Would this be in 2D or 3D?

    You can attach a Collider to a block, and a Rigidbody to your Player, to prevent them from passing through it. However, the NavMesh may also need updating depending on how the Player is controlled. Is this for a Point-and-click game, or one with Direct movement?

    If you're using 3D, you should be able to rely on Unity's updated Navigation system, which supports re-baking at runtime. In 2D, though, things'll be more complex because the NavMesh is based on a pre-set collider shape.

    If you can share more details / screenshots, it'll help clarify the situation.

  • It's 2d, point and click. (though I was thinking of adding the option to use WASD to move as well)

    we don't have it implemented yet, but I do have a sketch of the basic idea. It's a bunch of boxes the player has to push in a way that they can get through.
    (and a general screenshot of the game for reference)

    https://imgur.com/a/xmgeOpO

  • edited September 2023

    Thanks for the details.

    2D point-and-click is the tricky one - as you can't rely on collision nor dynamic rebaking to limit movement on the NavMesh.

    If the boxes are always arranged in a grid, however (at least when not moving), you might be able to get by with some NavMesh trickery.

    One approach would be to associate each grid space with a "NavMesh hole" that gets turns on/off as a box occupies/unoccupies it, via the Scene: Change setting Action. But, I would first try out the use of A* pathfinding.

    AC has an implementation of this on the Downloads page, and this pathfinding algorithm works by dividing a NavMesh up into a grid.

    It's also the case that - if an NPC stands on a cell in this NavMesh grid - then that cell becomes unnavigable.

    What I'm thinking is: if you were to build your NavMesh with an A* grid whose cell sizes matched those of the boxes, you could attach an NPC component to each box and have each cell that they occupy be automatically excluded from the pathfinding.

    It's a bit difficult to explain, but hopefully makes more sense in context. In a copy of the scene, implement the A* integration following the package's Readme, and then see if the above sounds like a workable approach.

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.