Jump to content

Stacking or lining up cubes


Rick
 Share

Recommended Posts

If I have a cube already in my scene, and I do a mouse pick on any of the sides I would like to place another cube that lines up with the side I clicked. All the sides of the cubes are the same in texture so rotation doesn't matter, and all the cubes are the same size.

 

So if I'm using CameraPick to get the selected point of a cubes size, how can I line up another cube perfectly on that side?

 

My first thought was to place the new cube directly at the same location of the clicked cube and then just offset it by 1 (in my case the cubes are all 1x1x1) in the direction of the face that was clicked, Just not sure how to figure out what direction to offset based on the face of the cube that was clicked. Must be some local coord value I can get perhaps?

 

Or if anyone else has another way I'm open to hearing it :)

Link to comment
Share on other sites

..you could also do some cube construct class, where you will create cube out of 6 quads, where each quad is pickable so you can out of box,just based on pick, find out which side to align new cube construct..also, its good approach like that because you can always disable(hide) any of cube quads if your gameplay require digging or such thing and its rather friendly for rendering..

 

Link to comment
Share on other sites

@Naughty nice idea. I'll keep it simple for now and see how performance goes. I'm doing this a little different than minecraft in that the entire world isn't built with cubes so not sure if I'll need to worry that much about performance. My idea is more of like a FPRTS where you can build structures from cubes, but the terrain is normal and there are normal trees and stone models that you can gather resources from. So given that, there is no digging of the earth. The idea is to then add a multiplayer element that is a persistent world where people can attack each other and structures. So sort of a survival game.

 

@macklebee so if I was using Lua just use the normal field of the pick table? (pick.normal). So that just has like a 1 or -1 in the x, y, or z value? Never used that normal field before.

Link to comment
Share on other sites

What am I missing with this code. It does enter this section when I click another cube, but I don't see anything. I print out pick.normal.x, y, & z and it has the right values or +/- 1 so not sure why my cube doesn't seem like it's getting offset

 

the block variable is a cube I create at startup

 

if GetEntityKey(pick.entity, "type") == "block" then
local c = CopyEntity(block)
--Notify(pick.normal.x.." "..pick.normal.y.." "..pick.normal.z)
PositionEntity(c, Vec3(EntityPosition(pick.entity, 1)), 1)                                   -- position the new cube at the picked cube location
MoveEntity(c, Vec3(pick.normal.x, pick.normal.y, pick.normal.z), 1)               -- offset the new cube from the picked cube
else

 

nvm got it with

 

local pos = EntityPosition(pick.entity, 1)
pos.x = pos.x + pick.normal.x
pos.y = pos.y + pick.normal.y
pos.z = pos.z + pick.normal.z

PositionEntity(c, pos, 1)

 

Thx

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...