0
\$\begingroup\$

I am still in the think-ahead-and-plan stage of a project where I'll want the player to be able to drag-out blocks - tiles but a minecraft-like 3D block-world.

So my question is: how can you determine where the user wants to place a block?

Here's a random minecraft screenshot I found on the internet:

enter image description here

My game will not be first-person camera; the user will be able to click anywhere to place a block.

If the user clicks on the centre of that green cross I've marked, which just misses the stonework to its right, where should the block be placed?

Technically determining the ray under the mouse cursor is trivial.

Given a ray and computing its distance / intersection with all existing block faces, and knowing the blocks that have previously been placed e.g. the last placed block, how can you 'do the right thing' with regards ambiguous movement? What rule set can you use?

\$\endgroup\$
  • \$\begingroup\$ Typically you'd add the new block adjacent to the currently selected face. Is that what you're asking? \$\endgroup\$ – MichaelHouse Jul 4 '13 at 6:02
  • \$\begingroup\$ @Byte56 I've added a pic to explain; generally, I don't yet have a concept of 'currently selected face' - how would that work? \$\endgroup\$ – Will Jul 4 '13 at 7:37
  • 1
    \$\begingroup\$ In minecraft, the reticle at the center of the screen points to a cube. On that cube there are multiple faces. The face that the reticle is over is the currently selected face. So for example, the user is pointing at the top of a cube; The currently selected face is the top, and the new cube would be placed above that. Or if the user were pointing their reticle at the side of a cube, the new cube would be added to the side. \$\endgroup\$ – MichaelHouse Jul 4 '13 at 8:09
  • \$\begingroup\$ @Byte56 yes, I want free-form drawing with the mouse rather than a 1st person camera. I understand how minecraft does it, but that's different. \$\endgroup\$ – Will Jul 4 '13 at 8:42
  • 1
    \$\begingroup\$ That said, it would be simpler and probably easier for the user to understand if you only place new blocks on the face of whatever visible block is directly under the reticle. Set a maximum distance limit if you don't want it to hit the wooden structure in the background, and make the user move the camera until they can see the face of the stone block where they want it placed. \$\endgroup\$ – LLL79 Jul 4 '13 at 9:30
5
\$\begingroup\$

The process is the same as with a reticle that's fixed to the center of the screen as with a reticle that moves with the mouse. I'm familiar with the idea of 3rd person placement of cubes, I've implemented exactly that in my game Age of Goblins.

New cubes are place adjacent to the selected face. The selected face is found by casting a ray from the camera, and detecting the cube and cube face the ray first passes through. For example:

enter image description here

The grey outline shows the selected face. When a cube is added it's placed adjacent to the selected cube, in the direction of the selected face.

This is fairly intuitive for users, since they're likely not expecting to be placing cubes floating in the air. So they expect them to be attached to something, and that something is the selected face of the cube they currently have selected.

You can kind of see a short example of it in action in this video at the 1:24 mark.

\$\endgroup\$
  • \$\begingroup\$ fun fact: I've been watching your youtube videos before, paying particular attention to the water flow stuff. Lovely work, hope AoG becomes big! \$\endgroup\$ – Will Jul 4 '13 at 18:18
  • \$\begingroup\$ @Will Thanks. It's fun stuff, I'll try to make AoG great. \$\endgroup\$ – MichaelHouse Jul 4 '13 at 18:21
  • \$\begingroup\$ I've done a little prototyping and this approach works great from a first-person perspective, when it makes sense to build towards the camera. In a 3D world with a roughly isometric outlook, this tends to encourage the user to build staircases towards the camera! So I'm experimenting with a dragging 2D rects of tiles instead. But I accept this answer, which is generally true. \$\endgroup\$ – Will Jul 8 '13 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.