# Pathfinding

## Recommended Posts

Hi everyone

I'm implementing a 3d map with just some squares and I wanna know what's the best way to make a pathfinding algorithm between these squares...

My first thought was loading a mesh with just the path, but i'm not sure what will i need to implement and what babylon already has.

Can someone give me some tips? I already implemented the A*, but just with divs...

##### Share on other sites

Yeah, I know some of these and, as I said, I already implemented a A* algorithm at http://pathfindingus.hol.es/

My real question is, what's the best way to make my pathfinding algorithm(yeah, I know I'll need a mesh based one) interact with my loaded mesh? Should I use the physics engine included in Babylon or is there a simple way of doing that?

##### Share on other sites

You could raycast to check if the grid is free to walk on or not but i personally would not do that

i would have a object like this

var collisionData = {};

collisionData[x+"|"+z] = true;

//remove a blocked position
delete collisionData[x+"|"+z]

//check if position is blocked
if(x+"|"+z in collisionData)

##### Share on other sites

Do you mean having an object with the grid of the walkable path? I was wondering doing it with navmesh, like this with Three.js http://nickjanssen.github.io/PatrolJS/demo/demo.html

I've researched something with recastjs but i was not able to figure it out how it works.

##### Share on other sites

if you want to check with a ray you could do it like this

//length to check higher length would result in less checks but low resolution
var length = 1;

//create a vector3 that points to the right you would need to check all directions
var right = new BABYLON.Vector3(1, 0, 0);

//position of the grid we are currently checking from
var position = new BABYLON.Vector3(x, y, z);

//cast a ray from the position to the right  to see if the right is free
var ray = new BABYLON.Ray(position , right, length);
var pickingInfo = scene.pickWithRay(ray, function (item) {return item.checkCollisions == true;});
//we return true for meshes that have there checkCollisions set to true
if (pickingInfo.hit){
//the ray hit so its not free to move to the right
}

more about the ray can be found here http://doc.babylonjs.com/classes/2.3/Ray

##### Share on other sites

So, the answer is yes, i'll have to implement my navmesh algorithm checking the collisions right? I thought there was an easier way of doing that since Babylon has a physics framework included. Anyway, thanks for your help!

##### Share on other sites

i'm not aware of something built into babylon but i'm still a noob maybe someone who has more experiences could say if there are any built in classes to help with path finding

##### Share on other sites

I'm not expending time trying this right now, cause I have more to do first. I'm just doing researches and everything heads me to implementing my own with the physics engine or using recast.js, but the demos doesn't even work for me and I don't know what i'm doing wrong... Is there some other opinion? UP!

##### Share on other sites

AFAIK, there's no built-in path finding function in the BJS framework. You have to use any external library.

##### Share on other sites

anyone? any help?

##### Share on other sites

This is not a directly related bjs question  I'm not really experienced with path finding algorithms

##### Share on other sites

I'll try something loading a mesh only with the path and making logic with its BoundingInfo... may it work? Thanks everyone

##### Share on other sites

• 1 year later...

has anyone tried these libraries with any bjs?

On 2/17/2016 at 4:17 PM, Suphi said:

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.