masterdon Posted June 20, 2017 Share Posted June 20, 2017 Hi Team, I have got a demo for 2D planner here DEMO 1 : http://www.babylonjs-playground.com/#SUXKHY#28 The yellow box meshes are draggable horizontally and vertically(go give it a try....). Now, I wanted to prevent dragging over the places where yellow box already exist(prevent collision of yellow box). In order to do that, I have made some changes in demo 1 to implement moveWithCollisions : Demo 2(using moveWithCollisions) - http://www.babylonjs-playground.com/#SUXKHY#32 Changes done: 1) Used checkCollisions and set ellipsoid(equal to width,height,depth of box) for yellow boxes: At Line : 39 - 40 box.checkCollisions = true; box.ellipsoid = new BABYLON.Vector3(sWidth, sHeight, sDepth); 2) set gravity to scene and gravity with ellipsoid to camera(not sure if this is needed as i want prevent collision among yellow boxes): At Line : 72-75 scene.gravity = new BABYLON.Vector3(0, -9.81, 0); camera1.applyGravity = true; camera1.ellipsoid = new BABYLON.Vector3(1, 1, 1); 3) enable collision for scene and camera At Line : 76-77 scene.collisionsEnabled = true; camera1.checkCollisions = true; 4) For horizontal dragging, moveWithCollisions for translating x instead of setting position.x (commented that code, line 194) : At Line : 195 currentMesh.moveWithCollisions(new BABYLON.Vector3(currentMesh.minxpos + Math.round((currentCursorXPosition - currentMesh.minxpos) / horizontalSlotWidth) * horizontalSlotWidth, currentMesh.position.Y, currentMesh.position.Z)); 4) For vertical dragging, Use moveWithCollisions for translating z instead of setting position.z (commented that code, line 201) : At Line : 202 currentMesh.moveWithCollisions(new BABYLON.Vector3(currentMesh.position.Z, currentMesh.position.Y, currentMesh.minzpos + Math.round((currentCursorZPosition - currentMesh.minzpos) / verticalSlotHeight) * verticalSlotHeight)); However, the dragging is completely gone now. what am i missing here Quote Link to comment Share on other sites More sharing options...
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.