Rick Posted October 10, 2011 Share Posted October 10, 2011 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 Quote Link to comment Share on other sites More sharing options...
macklebee Posted October 10, 2011 Share Posted October 10, 2011 if its just a simple 1x1x1 cube then just find the normal of the pick and use that to offset from the origin of the picked cube... simple and straightforward. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Naughty Alien Posted October 10, 2011 Share Posted October 10, 2011 ..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.. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 10, 2011 Author Share Posted October 10, 2011 @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. Quote Link to comment Share on other sites More sharing options...
macklebee Posted October 10, 2011 Share Posted October 10, 2011 assuming that the picked cube is aligned with the global axis, then yes the pick.normal will return 1/-1 for the x, y, or z... but yes, pick.normal is the field needed. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rick Posted October 10, 2011 Author Share Posted October 10, 2011 Cool thanks. Will give that a try tonight. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 10, 2011 Author Share Posted October 10, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.