Jump to content

How to create a grid whose cells can be accessed in BABYLON ?


Recommended Posts

  • 1 month later...

Hi Rohan!  Wow, sorry you have not gotten any replies in SO LONG.  This is insane.  Have you had any success?

Generally speaking, you will need to determine which "tile" (which subMesh) of a tiled ground ...a mesh is located-over... by doing some calculating. 

And you don't NEED to use tiled grounds, either.  A standard ground would work just fine, too, if you know the number of subDivisions and the size of the ground.  There are fancy methods, too, possibly by shooting a "picking ray" straight down from the mesh, and gathering the ground location from the 'pickingInfo' object that returns.

Here is a playground demo that uses it...


Open your console.  You'll see the X and Z values displayed.  The picking ray stuff is at lines 137-145 area... inside the renderLoop.  In your case, I don't think you will need to put it inside the renderLoop.  Your issue might be more... "Hey mesh... run your mesh.whatsMyLocation() function and report.".  But then again, you could just check the mesh.position and learn where it is.  *shrug*

But, the picking ray version does have ONE advantage.  If the mesh is not 'over' the ground, the picking ray will report NO HIT... and you might want to know when that is true. *shrug*  Then again, it will be a simple calculation to determine if your mesh is off-ground... by analyzing its .position and knowing the dimensions of your ground plane.

Tiled grounds are a bit different... and I'm far from an expert on them, and the 'subMesh' that they use.  It may be possible to use the picking ray to determine which subMesh (which tile) the picking ray 'hit'.  Not sure.

I hope some of this helps, and sorry again for the slow response.  Be well!

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.

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.


  • Recently Browsing   0 members

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