I’ve been working on a 2d minecraft clone, and i have yet to add building and mining. How do I implement this, i need to be able to highlight the block i want to break or place on, and if i want to place on in, i need to determine which side of the block to do it on. Also, on hightlighting blocks, i would like it to only hightlight the block that a raycast from the players head on the direction of the mouse hits, as opposed to the block the mouse is on.
Here is one way of doing it. You need to use “Snap to grid” extension.
But keep in mind that this is a very clumsy method for example purposes only. There are functions here that we could do without and not perform them every frame. Also i diceded to allow the player to build throug wall if its within his reach, which may not be what you want.
I sketched out a small prototype, it’s a little simpler than the last one. I have not tested this mechanic in real game situations, there may be bugs. Simple Minecraft Prototype.