Unable to call ActionManager with castRay

Hello,
My playground: https://playground.babylonjs.com/#UGIGWU#37

I am trying to create a 3d version of hangman, and so far I have made a moveable character with a PointerLock. I have been using 26 box meshes as my controls for the hangman, with 1 box per letter, but I am having trouble getting rid of the boxes when I click on them. Previously, I created an individual action manager for each box that I used to call from a castRay function, but since then, I made a function to create all of the boxes in a loop rather than doing it manually, and now I don’t know how to call the action manager for each box. All the boxes are under a general action manager. My problem now is I that don’t know what is the problem, my castRay function, or my general action manager, and I don’t know how to fix either. For the general action manager, I might’ve used the wrong function to disable the box, but I don’t know what the right one would be (I started using Babylon yesterday so sorry for my lack of knowledge). For the CastRay function, I don’t know if I’m even calling the mesh that I want to. If you’re wondering how I made the mouse pointer not misfire when clicking elsewhere on the screen to trigger the pointer lock, I created 4 invisible planes that cover every part of the screen except the center, so only the ray from the camera should be registering(lines 216-238). I have been able to shift around my code so that the mouseclick is detected when I put the mouse in the center of the screen, but I would like a cleaner fix that allows me to use the castray function I created.

In summary: I have 26 box meshes that I created with a for loop that are all connected to one action manager, which I would like to click with the crosshair in the center of the screen. But either the general action manager or the castray function I made is faulty, and I do not know what the problem is, or how to fix it. Lines 135-190 are likely where the problem lies.

check this PG
As a result, it was converted into a case when a hit occurred without the need for an action manager.

the overall problem
Inside the onPointerObservable event
I just declared an unknown mesh, not a hit mesh.
Also, it seems that the action event of the mesh was not declared (I think it was a mistake while simply creating a case).
If you want to see the pg and change it to a form other than this form, please comment.

2 Likes

Thank you so much for the solution and explanation! I had resorted to creating each object individually, which was time-consuming, to say the least. I never realized I forgot to declare the action event for the meshes, so this makes me feel a little better. I just started learning JS and using BabylonJS on Thursday, so sorry for the simplistic/newbie question.

2 Likes

Asking easy or introductory questions is relative, but I think it’s a good way to jump up faster anyway.

2 Likes