Majeed Siddiqui Posted August 8, 2016 Share Posted August 8, 2016 I would like to create boxes of random size that should align with grid squares. For example, if grid is 8x8 square and there is a box of size 2x3 then it should exactly take 2x3=6 square on grid. Is there any way to force this? Actually I want have drag and drop for those boxes that's why this restriction is needed. Or do I have to do maths stuff to force this? Something like shown in image. http://www.babylonjs-playground.com/#26LMDE#0 I am using one of these to implement grid: Quote Link to comment Share on other sites More sharing options...
georage Posted August 8, 2016 Share Posted August 8, 2016 I suggest doing a hit test (see tutorial playgrounds) when you drop the box and see which square it should snap to. You will have to use math! But you could easily make it snap to a random side or corner. I am working on something similar using 3D cubes. Not code to share yet! Majeed Siddiqui 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 8, 2016 Share Posted August 8, 2016 Hi guys! http://playground.babylonjs.com/#HHFBT#2 I modified our drag'n'drop playground demo... added a little value-rounding. I used a 500x500 grid divided 50 times, so each cell is 10x10. Lines 89-92 are the rounding function, of course. Line 109 is where we use the rounding on our X and Z values, but leave Y value alone. Diff is the AMOUNT of change, and it is added to the current mesh.position... in line 112. Looks like it works. This is only for dragging. You will still need to position your mesh at proper places on the grid.... when you CREATE the mesh. Some might call that initial positioning... "calibration-to" or "synchronizing-with" ...the grid. You need to "sync-up", first thing, after mesh creation/import. There's still one minor problem. The wireframe grid (called ground2) also let's you drag IT around, and ground2.isPickable = false doesn't stop it from being so. Oh well, a good secondary challenge. Hope this helps. Party on! Majeed Siddiqui, abhivaidya and georage 3 Quote Link to comment Share on other sites More sharing options...
georage Posted August 8, 2016 Share Posted August 8, 2016 Wingnut, I hope you are well paid. Thanks for that cool example. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 8, 2016 Share Posted August 8, 2016 All volunteer... of course. We're all friends and family, and "the cause" is excellent, here, so no invoicing/billing. Yes, I AM paid well, when you push that LIKE button. Thanks for those and for the kind words. That's plenty of pay for me. Thank YOU for helping, too. jerome, GameMonetize, JohnK and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Majeed Siddiqui Posted August 9, 2016 Author Share Posted August 9, 2016 You are the best!! Thanks a lot! 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.