how to create a block placement system like in Solomon's Key

The easiest way to explain is to show you a video of it being used in a old NES game

Basically i want to create a grid system that when the players hits a button it creates ablock in the closest grid position. This is for a 2d platformer.

1 Like

Hey man! I’ve been working on a prototype for your problem, it can serve you as a starting point maybe!
It looks like this

Controllers:

  • Left Arrow to go left
  • Right arrow to go right
  • Up arrow to jump
  • Space to place blocks

It’s a basic character controller with a “magic stick” attached as a child object and a “block dispenser”. The block dispensers is in charge of instantiating the blocks in the correct position. All the sprites are set to 128 px per unit so I can easily place the tiles at absolute positions. If the block dispenser is at x=1.34 y=1.46 the dispenser rounds up to 1,1 and places the object in that position.

if (Input.GetKeyDown(KeyCode.Space))
{
            if(hit.collider == null)
                if (block){
                    Vector2 position = new Vector2(Mathf.RoundToInt(gameObject.transform.position.x), Mathf.RoundToInt(gameObject.transform.position.y));
                    Instantiate(block, position, Quaternion.identity);
                }
}

Since every tile is 128x128 there’s no overlapping adn every tile fits perfectly

I used kenney assets, you can clone it from my github and use it however you want.

Hope this helps!

thats fantastic, thank you!