Jump to content

Build grid from existing scene for path finder


TomaszFurca
 Share

Recommended Posts

Hi! I think about add path finder to my MMOGame. To do that I want use easystar. I looking for rebuild my scene to grid for pathfinder. it is very simple grid multidimensional array with positions. I just need X and Z, because i do not use Y for movement. So my question is... The best function for detect unwalkable fields (meshes like tree, stone, ground Y<0 AND Y >0) is ray? 

How i want to do that:

Get minX, maxX, minZ, maxZ of my ground. Then loop it for every length (1 vec) and check picked mesh or picked position if I pick ground. Then i can recognize unwalkable position and create grid.

 

Link to comment
Share on other sites

Not Sure!  but rather than looping every length(1 vec) as you said, you could loop through other meshes which are inside the scene. And using the boundingBox you can get their min and max X and Z. 
It's won't be accurate since we'll be using boundingBox but definitely fast. 
Let's see what others suggest :) 

Link to comment
Share on other sites

The best way to do this is to create a navigation mesh on your scene. Then when the user clicks on an area, if the navigation mesh is picked I move the character to that point on the mesh. 

 

    pointerDown(evt){
        let scene = this.scene;
        let pickResult = scene.pick(scene.pointerX, scene.pointerY);
        if (pickResult.pickedMesh == scene.getMeshByName("Navmesh")) {       
            this.player.trigger('move', pickResult.pickedPoint.clone()) //player.action
        } else {
            this.showActionMenu(pickResult.pickedMesh, scene)
        }
    }

 

Heres some resources for baking a nav mesh.

https://docs.blender.org/manual/en/dev/game_engine/physics/types/navigation_mesh.html

https://www.youtube.com/watch?v=aMWeTXL98mM

You can checkout my code here and see demo here

Also, Wanadev created a pathfinding library for babylonjs that uses the A* search algorithm to find a path on a nav mesh.

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