avisangray Posted June 25, 2018 Share Posted June 25, 2018 i'm trying to create a simple game using babylon but stuck at a point where i need to detect * the mesh(s) that is directly below a mesh that is being dragged example - different food articles need to be placed on different types of plates let's say an ice-cream scoop is being dragged(pointermove event) on any of the plates which are close to each other after someone places a scoop on a particular plate (pointerup event) how to know which mesh or meshes is below that? a lengthy way is to loop through position of each mesh of plates(which are around 80 in number) with position of latest dragged mesh(ice cream scoop in this case) and find the right one above which ice cream is. is there any other efficient method? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted June 26, 2018 Share Posted June 26, 2018 The best way I know of is to raycast from the ice-cream scoop position (origin). Direction is down: https://doc.babylonjs.com/babylon101/raycasts edit: use multi-pick if you are hitting food on a plate. Not sure exactly how your scene works. Quote Link to comment Share on other sites More sharing options...
Arte Posted June 26, 2018 Share Posted June 26, 2018 Hi @avisangray and welcome, Small multiPick PG what @brianzinn have in mind. Just open console. Quote Link to comment Share on other sites More sharing options...
babbleon Posted June 26, 2018 Share Posted June 26, 2018 Hi @Arte, Does this multiPick show what is below the sphere or what is behind (on screen) the sphere. I think the same feature / problem happens with the Drag & Drop demo - you can only drag the shapes when you click on the screen where the ground is behind it (on screen). I don't have anything to add to this or any suggestions of what could help.. just wanted to ask the question. Quote Link to comment Share on other sites More sharing options...
adam Posted June 26, 2018 Share Posted June 26, 2018 This PG might be helpful: https://www.babylonjs-playground.com/#1UZIZC#33 Arte and babbleon 1 1 Quote Link to comment Share on other sites More sharing options...
babbleon Posted June 26, 2018 Share Posted June 26, 2018 Cheers @adam - it is! Thank you. Quote Link to comment Share on other sites More sharing options...
Arte Posted June 26, 2018 Share Posted June 26, 2018 Each multiPick mesh have distance to camera. From distances you can figure out which is nearest or the furthest. Quote Link to comment Share on other sites More sharing options...
avisangray Posted June 27, 2018 Author Share Posted June 27, 2018 hey @Arte @adam @brianzinn Thanks a lot it worked like charm!!!! could you also help with animation? i'm using registerBeforeRender which works perfect. however issue is i need to chain animations using input controls. i tried BABYLON.Animation class but i'm unable to get a linear animation with it. some trouble understanding keys i believe if i keep the values same it doesn't do anything. however it does works if i keep different value for each key. but as i said i need linear animations. Quote Link to comment Share on other sites More sharing options...
avisangray Posted June 28, 2018 Author Share Posted June 28, 2018 Ok so I'm using setinterval now and it serves the purpose. Basically I'm just rotating a mesh as per user action. So registerbeforerender didn't had an exit or maybe I wasn't able to find how to just remove it from scene.(except that you could add it to a function, stop the action (rotation) using comparison if statement for an incremental variable - however I was pretty unsure and concerned about it's efficiency. Since function could be called for upto 300 times per user session) Anything better? 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.