Kaushik Posted January 31, 2016 Share Posted January 31, 2016 Question is about my half complete game. Here is my game: http://www.babylonjs-playground.com/#KBHU0#12 Use Arrow Keys to turn the cube. Game objective is to align the cube to catch the same color slab. Question: When the slab hit the cube (function checkHit()), how do I decide if the color of slab and the that side of the cube is the same? I am new to game development. Any suggestions on my code is very welcome. Another question: Press Up (watch direction of turn), then press Left, now again Up - notice that direction is reversed. How to correct this (to keep the same direction)? -Kaushik Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 1, 2016 Share Posted February 1, 2016 Hello you should use scene.pickWithRay to decide which face should be selected: http://doc.babylonjs.com/classes/2.2/Scene#pickwithray-ray-predicate-fastcheck-rarr-pickinginfo-classes-2-2-pickinginfo- For your second question you can use mesh.rotate (http://doc.babylonjs.com/overviews/How_Rotations_and_Translations_Work) with local system reference Kaushik 1 Quote Link to comment Share on other sites More sharing options...
Kaushik Posted February 1, 2016 Author Share Posted February 1, 2016 Than you for reply. However I am still lost. Once I call pickWithRay, how I do I find out which side (face) of the mainCube it hit? var rayPick = new BABYLON.Ray(slabObj.slab.position, mainBox.position); var pickInfo = scene.pickWithRay(rayPick, function (item) { console.log("Found hit", item); }); console.log("PickInfo", pickInfo); Callback function does find mainCube. But the pickInfo.hit is false! Side question: Why the 2 callbacks are fired by pickWithRay? Is it for each side of the cube? Check line 92 on http://www.babylonjs-playground.com/#KBHU0#14 Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 1, 2016 Share Posted February 1, 2016 pickwithray doesn't work with callbacks. See the doc here: http://doc.babylonjs.com/classes/2.2/Scene#pickwithray-ray-predicate-fastcheck-rarr-pickinginfo-classes-2-2-pickinginfo- The second parameter is a function that should return 'true' if the mesh can be selected, or 'false' if it isn't. That's why it's called twice in your example: you have 2 meshes. Kaushik 1 Quote Link to comment Share on other sites More sharing options...
KosLooney Posted February 3, 2016 Share Posted February 3, 2016 Hey kaushik, The 2nd parameter needs to be a direction, not the position from the mainbox (which is BABYLON.Vector3(0, 0, 0)). http://doc.babylonjs.com/classes/2.2/Ray example: var rayPick = new BABYLON.Ray(slabObj.slab.position, new BABYLON.Vector3(0, -1, 0)); back BABYLON.Vector3(0, 0, -1). down BABYLON.Vector3(0, -1, 0). forward BABYLONVector3(0, .0, 1). left BABYLON.Vector3(-1, 0, 0). right BABYLON.Vector3(1, 0, 0). up BABYLON.Vector3(0, 1, 0). 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.