- Home /
Add object to another object's selected face
Hello, I've been strugling for the past few days to create a simple system to add a object, (cube for example) next to another object's face the same way minecraft does it. Anyone have any ideas? Probably share a bit of code?
Answer by Jesse Anders · Jan 23, 2011 at 03:51 PM
I answered a similar question recently (maybe it was yours)?
Anyway, to do something like Minecraft, you probably want to use a grid system in order to ensure that the results are deterministic (rather than, for example, computing the coordinates for the new cube relative to the coordinates of another cube).
With this method, each cube would have its own integer 'grid coordinates'; the actual world position would then just be a scalar multiple of the grid coordinates (possibly with other transformations applied if desired).
When raycasting against a cube, you'll get a normal back if there's a hit. From this normal, you can determine what side of the cube was hit, and also in which direction in 'grid space' the corresponding neighboring grid cell is. You can then create a new cube in that grid space.
Hmm it is the first question related to "$$anonymous$$ecraft style" content I'm asking, but I have a little doubt that this isn't going to work right. Im thinking this because if you go "below or beyond" the grid, there might be complications and the results are wrong.
The grid can be implicit or non-bounded, so there shouldn't necessarily need to be any 'below or beyond'. The point is simply to give each cube a set of integer coordinates, both for deter$$anonymous$$istic placement and to be able to reason about the cubes in 'grid space', which will likely be useful. (Although I haven't implemented anything like this, I imagine the cubes are typically stored in a hash table or something, in which case the integer coordinates can serve as the source of the hash code for each cube.)
Answer by DavidDebnar · Jul 09, 2011 at 07:10 AM
Posting this like for the 5th time... First get mouse raycast, than when player presses for example LMB it instantiates a block and stores it into a var and than rounds that number to the grid size.
block.position.x = Mathf.Round(actualBlock.position.x); block.position.y = Mathf.Round(actualBlock.position.y); block.position.z = Mathf.Round(actualBlock.position.z);
Your answer
Follow this Question
Related Questions
How to make a block have highlighted lines like it does in minecraft 2 Answers
Creating multiple faces (cubes) 1 Answer
How to get Var from a obj 1 Answer
Place block script 1 Answer