Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YUKA findPath is not detecting any collisions in Babylon.js #77

Closed
orion3dgames opened this issue Jan 3, 2023 · 3 comments
Closed

YUKA findPath is not detecting any collisions in Babylon.js #77

orion3dgames opened this issue Jan 3, 2023 · 3 comments

Comments

@orion3dgames
Copy link

orion3dgames commented Jan 3, 2023

EDIT : I"VE RESTARTED THE DEMO SERVER AS IT WAS VERY LAGGY.


Hi there,

I've been trying for over a month to get YUKA integrated into my game with no success, but I refused to give up because it is exactly what I need and would be a tremendous amount of work to do myself.

PUBLIC REPO HERE: GITHUB REPO

DEMO HERE SHOWING ISSUE

CLICK FOR DEMO LINK HERE : As you can see, it looks like the navmesh & graph is loaded correctly but findPath is never false so I cannot detect any collisions.

WHAT IS WRONG AND WHAT AM I EXPECTING

I'm expecting foundPath constant below to be false when I move off the navmesh

SNAPSHOT OF MAIN CODE

// IMPORTS
import { NavMesh, Vector3 as Vector3Y } from "yuka";
import loadNavMeshFromString from "../../shared/Utils/loadNavMeshFromString";
import { createConvexRegionHelper, createGraphHelper } from "../../shared/Utils/navMeshHelper";

////////////////////// load navmesh
// https://github.com/oriongunning/t5c/blob/main/src/shared/Utils/loadNavMeshFromString.ts
this._navMesh = await loadNavMeshFromString(global.T5C.currentLocation.key); 

////////////////////// display navmesh
// https://github.com/oriongunning/t5c/blob/main/src/shared/Utils/navMeshHelper.ts
let navMeshGroup = createConvexRegionHelper(this._navMesh, this._scene)
console.log('NAVMESH LOADED', this._navMesh);

////////////////////// display navmesh graph
// https://github.com/oriongunning/t5c/blob/main/src/shared/Utils/navMeshHelper.ts
let graphHelper = createGraphHelper(this._scene, this._navMesh.graph, 0.2)

////////////////////// PLAYER MOVEMENT
// https://github.com/oriongunning/t5c/blob/main/src/shared/Entities/Player/PlayerMove.ts
const foundPath: any = this._navMesh.findPath(new Vector3Y( oldX, oldY, oldZ), new Vector3Y(newX, newY, newZ));
if (foundPath){
    this.nextPosition.x = newX;
    this.nextPosition.y = newY;
    this.nextPosition.z = newZ;
    this.nextRotation.y = this.nextRotation.y + (newRot - this.nextRotation.y);
    console.log('VALID position for', new Vector3Y( oldX, oldY, oldZ), new Vector3Y(newX, newY, newZ), foundPath);
}else{
    console.error('INVALID position for', new Vector3Y( oldX, oldY, oldZ), new Vector3Y(newX, newY, newZ, foundPath));
}

NAVMESH CAN BE FOUND HERE:

all navemesh can be found here: https://github.com/oriongunning/t5c/tree/main/public/models/navmesh

Many thanks,
Orion

@orion3dgames
Copy link
Author

orion3dgames commented Jan 5, 2023

Ok, after digging into yuka internal working, if I do the following change to yuka.js, everything works as I want....

I was assuming yuka returned an empty array if no valid path was found.... Does this mean, I'm not using using Yuka the way it was intended? Any suggestions?

image

@Mugen87
Copy link
Owner

Mugen87 commented Jan 5, 2023

I was assuming yuka returned an empty array if no valid path was found

That is unfortunately not correct. NavMesh.findPath() always returns a path. If the start and end points lie outside of the nav mesh, the implementation tries to find the closest region so a path can be returned.

Navigation is a complex topic in games. And doing it automatically right for all use cases is tricky for an AI engine. Depending on your application logic, you often know that the start and end position of a game entity lie on your nav mesh. Sometimes you don't and automatic region assignment is unwanted since you don't want the AI to move. In this case, use NavMesh.getRegionForPoint() to find out whether a point (e.g. the game entities destination point) lies insides the level/navmesh. If not, don't trigger a path search via NavMesh.findPath().

@orion3dgames
Copy link
Author

@Mugen87 Yes, I realize that now and it make sense 100%.

I cannot wait to dig in and see what I can manage to do. I think we can close this now.

Many thanks for taking the time to explain.

ps: i feel a little silly now spending over a month trying to figure it out, looking in the wrong area, and making assumptions.

@Mugen87 Mugen87 closed this as completed Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants