Hagop Posted March 14, 2016 Share Posted March 14, 2016 Hi all This might sound a simple question but i don't seem to to figure out the solution. I have a mesh for example a box (box = BABYLON.Mesh.CreateBox("box", 40, scene);. I have enabled collisions by using scene.collisionsEnabled = true; I also have a freecamera and another imported mesh for example a shelve which is at a fixed position. . If I try to move the freecamera through the sheve it collides and everything is fine. However, if I attach the box to the freecamera so that the box is constantly ahead of the freecamera scene.registerBeforeRender(function () { box.position.z = scene.activeCamera.position.z + 100 ; }); and as I move the camera and the box through the shelve the box passes through the shelve, whilst the camera collides with it. Using the code below I can verify that the box intersects with the shelve if (box.intersectsMesh(shelve, false)) { box.material.emissiveColor = new BABYLON.Color4(1, 0, 0, 1); } else { box.material.emissiveColor = new BABYLON.Color4(1, 1, 1, 1); } I have also added ellipsoid to the box but no difference box.ellipsoid = new BABYLON.Vector3(0.5, 1.0, 0.5);box.ellipsoidOffset = new BABYLON.Vector3(0, 1.0, 0); What am I missing? Quote Link to comment Share on other sites More sharing options...
eboo Posted March 14, 2016 Share Posted March 14, 2016 mesh move collision work with box.moveWithCollisions(BABYLON.Vectro3D(...)) only (i believe) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 15, 2016 Share Posted March 15, 2016 eboo is correct Quote Link to comment Share on other sites More sharing options...
Hagop Posted March 15, 2016 Author Share Posted March 15, 2016 bad news Quote Link to comment Share on other sites More sharing options...
iiceman Posted March 15, 2016 Share Posted March 15, 2016 Have you tried to move the box and append the camera to the box? Quote Link to comment Share on other sites More sharing options...
Hagop Posted March 15, 2016 Author Share Posted March 15, 2016 iiceman. I tried your suggestion by adding keypress event listeners to the box and make the freecamera to follow to the box but same problem. What do you mean by appending? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2016 Share Posted March 19, 2016 Hi Hagop. I'm just saying hi, and wondering if you have had any success. I think iceman meant... use mesh.moveWithCollisions to move your box with keypresses. And parent the camera to the box... or use a follow[Arc]Cam targeted to follow the box. Here... http://www.babylonjs-playground.com/#LYCSQ#315 ... is one of the nicest playgrounds EVER (not mine). It uses cursor keys and its full-powered moveWithCollisions sits at line 166. This uses a standard ArcRotateCam, but notice the sweet camera LERP in line 174 of the renderLoop. That gives the camera a nice lagging follow, eh? That's PRO stuff there, baby. Would your project work okay with ONLY the box having collisions, and no collisions on the camera itself? Or do you NEED camera collisions (along with box collisions)? Thoughts? Quote Link to comment Share on other sites More sharing options...
Hagop Posted March 20, 2016 Author Share Posted March 20, 2016 Hi Wingnut Thank you for the link. It looks great. No need for parenting.No need for keyboard entry as well (freecamera silently listens to them). I didn't want to use movewithcollisions but non the less. Here is part of the code I used. I need to check rotations further... scene.registerBeforeRender(function () { if(scene.isReady()) { registerCameraPosition = scene.activeCamera.position.clone(); registerCameraRotation = scene.activeCamera.rotation.clone(); xDiff = registerCameraPosition.x - registerCamera_lastPosition.x; yDiff = registerCameraPosition.y - registerCamera_lastPosition.y; zDiff = registerCameraPosition.z - registerCamera_lastPosition.z; globalCart.rotation.y = scene.activeCamera.rotation.y ; globalCart.moveWithCollisions(new BABYLON.Vector3(xDiff,yDiff,zDiff)); Quote Link to comment Share on other sites More sharing options...
iiceman Posted March 20, 2016 Share Posted March 20, 2016 Yeah, Wingnut is right. I meant the parenting.. but well, if you update the camera position yourself, that's cool, too. 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.