George3D Posted February 7, 2017 Share Posted February 7, 2017 I'm working with Sprites and using "pickSprite" and "pickedSprite" in this code: spriteManager.isPickable = true; player.isPickable = true; var pickResult = scene.pickSprite(event.clientX, event.clientY); pickResult.pickedSprite.cellIndex = 1; It's part of a program with a crawling bug you have to hit with a mouse click. But there is no hit possible. Only if the bug doesn't move I can hit it with the mouse. Quote Link to comment Share on other sites More sharing options...
George3D Posted February 7, 2017 Author Share Posted February 7, 2017 I found another (longer-winded) way: function pickIntersect (point, pos, diff) { if ((point.x > pos.x-diff) && (point.x < pos.x+diff) && (point.z > pos.z-diff) && (point.z < pos.z+diff)) return true; return false; } if (pickIntersect(pickResult.pickedPoint, player.position, 2)) player.cellIndex = 1; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 7, 2017 Share Posted February 7, 2017 Hello! do you mind creating a small repro in the Playground? I'll check it then Quote Link to comment Share on other sites More sharing options...
George3D Posted February 8, 2017 Author Share Posted February 8, 2017 I copied the shortened Code in the Playground: http://www.babylonjs-playground.com/#26ZKJD#0 I used an image file with 2 cells (0 = normal; 1 = squashed). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 8, 2017 Share Posted February 8, 2017 I see no image. But I also see no issue (I console.log when squashed) Quote Link to comment Share on other sites More sharing options...
George3D Posted February 8, 2017 Author Share Posted February 8, 2017 I didn't know how to get the image into the Playground. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 10, 2017 Share Posted February 10, 2017 Even without the image, you can just console.log when hit to see that it is working. But one thing: you should not add the click event on the window because you will capture all clicks event outside the canvas. You should instead use the scene.onPointerObservable: http://doc.babylonjs.com/classes/2.5/scene#onpointerobservable-observable-classes-2-5-observable-lt-pointerinfo-classes-2-5-pointerinfo-gt- Example here: http://www.babylonjs-playground.com/#10OY8W#5 To get the correct X and Y for the mouse you can use scene.pointerX / Y Quote Link to comment Share on other sites More sharing options...
George3D Posted February 11, 2017 Author Share Posted February 11, 2017 Thank you your efforts, in the meantime I found out: the picking is working. It's my problem, I hit the bug very rarely. Thanks also for the "click-hints". And a new question: What ist the difference between clientX/Y and pointerX/Y? Both seem to work equally. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 13, 2017 Share Posted February 13, 2017 the pointerX/Y takes in account DPI 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.