manofstature Posted November 13, 2015 Share Posted November 13, 2015 Hi! I seriously do not know how to do this. I use the ActionManager, like so: antagonist.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, antagonist, "scaling", new BABYLON.Vector3(2, 2, 2), 1000)). I can click on a mesh and it performs the intended action, but I have the pointer lock implemented, as it is a first person game, so the cursor disappears. How do I enable that same action when my camera is centered on the mesh and I press the left mouse button? Any ideas? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 13, 2015 Share Posted November 13, 2015 Hello and welcome! you will have to do a scene.pick on every frame (from the middle of your screen..like 800/2, 600/2 if your canvas size is 800x600) to find if a pickable object is there and if pick returns a hit then start your animation. PG about picking: http://babylonjs-playground.com/?11PG about animations: http://babylonjs-playground.com/?7 Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 13, 2015 Share Posted November 13, 2015 There is a new public callback in 2.3 - onPointerMove, which can be used like this - http://www.babylonjs-playground.com/#2F1ZUDmight be helpful as well. Quote Link to comment Share on other sites More sharing options...
iiceman Posted November 14, 2015 Share Posted November 14, 2015 I think I did pretty much the same as Deltakosh suggested but instead of scene.pcik I sued scene.pickWithRay I think. I cast a ray from the camera position to the current camera target and check to see if the ray hit something. Not sure why DK and RaananW suggest that it has to be done on every frame or while moving the mouse. If I understand you right you just want to check on click, right? Like shooting stuff.. Okay, example is better than explaining I guess. Is something like that what you want: http://p215008.mittwaldserver.info/Maze/ ? If so, you can look at the code. It's a bit messy but in the Player.js you find this part that happends on the mosuedown event:// pick rocket impact positionvar ray = new BABYLON.Ray(player.position, player.getTarget().subtract(player.position));var pickInfo = scene.pickWithRay(ray, function(mesh){ return mesh == mazeMesh;})It casts the ray from the camera position (in my case I just called it player) in the direction of the camera target and checks if the wall of the maze got hit. Hope that helps... somehow ... if not I think I can could create a little playground to show what I mean. Let me know if I should. Quote Link to comment Share on other sites More sharing options...
manofstature Posted November 14, 2015 Author Share Posted November 14, 2015 Thanks for the help! I think I did pretty much the same as Deltakosh suggested but instead of scene.pcik I sued scene.pickWithRay I think. I cast a ray from the camera position to the current camera target and check to see if the ray hit something. Not sure why DK and RaananW suggest that it has to be done on every frame or while moving the mouse. If I understand you right you just want to check on click, right? Like shooting stuff.. Okay, example is better than explaining I guess. Is something like that what you want: http://p215008.mittwaldserver.info/Maze/ ? If so, you can look at the code. It's a bit messy but in the Player.js you find this part that happends on the mosuedown event:// pick rocket impact positionvar ray = new BABYLON.Ray(player.position, player.getTarget().subtract(player.position));var pickInfo = scene.pickWithRay(ray, function(mesh){ return mesh == mazeMesh;})It casts the ray from the camera position (in my case I just called it player) in the direction of the camera target and checks if the wall of the maze got hit. Hope that helps... somehow ... if not I think I can could create a little playground to show what I mean. Let me know if I should. Nice, I was thnking about doing something similar, just didn't know how to start.. If you could create a playground I would be very grateful. I implemented the mouseListener event to show the name of the mest I hit with the ray, but it just return undefined. Need to iron it out a bit. Quote Link to comment Share on other sites More sharing options...
iiceman Posted November 15, 2015 Share Posted November 15, 2015 Okay, I'll create one for you tomorrow Quote Link to comment Share on other sites More sharing options...
iiceman Posted November 15, 2015 Share Posted November 15, 2015 Okay, here we go: http://www.babylonjs-playground.com/#1WIOXI It feels a bit weird because it starts the picking even if you turn the camera, but that won't happen anymore since you use the pointer lock later. I hope it helps. If you have any questions just shoot Quote Link to comment Share on other sites More sharing options...
manofstature Posted November 15, 2015 Author Share Posted November 15, 2015 Okay, here we go: http://www.babylonjs-playground.com/#1WIOXI It feels a bit weird because it starts the picking even if you turn the camera, but that won't happen anymore since you use the pointer lock later. I hope it helps. If you have any questions just shoot Very, very nice, thank you for this! 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.