Jump to content

Interaction with meshes while the pointer is locked


manofstature
 Share

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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/?11

PG about animations: http://babylonjs-playground.com/?7

Link to comment
Share on other sites

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 :D

 

... if not I think I can could create a little playground to show what I mean. Let me know if I should.

Link to comment
Share on other sites

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 :D

 

... 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. :D

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...