Jump to content

Pathfinding


MauJovi
 Share

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

Thanks in advance!

Link to comment
Share on other sites

First, thank you for your reply.

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?

Link to comment
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 = {};

//add a blocked position
collisionData[x+"|"+z] = true;

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

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

Link to comment
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

Link to comment
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!

Link to comment
Share on other sites

  • 1 year later...

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