Recast Navigation

Yo @Cedric … That get Next path function you exposed… Thats safe to call each frame right?

Also… Do you no of a way to detect if we are on the off mesh link… some kind of isOffMeshLink when traversing an Off Mesh Link… OR does recast already have that property and its not exposed ???

Still getting Error with emsdk 1.38.33

Mackeys-Mac-Pro:RecastJS mackey$ source "/Users/Mackey/Tools/emsdk-1.38/emsdk_env.sh"
Adding directories to PATH:
PATH += /Users/Mackey/Tools/emsdk-1.38
PATH += /Users/Mackey/Tools/emsdk-1.38/fastcomp/emscripten
PATH += /Users/Mackey/Tools/emsdk-1.38/node/12.18.1_64bit/bin
PATH += /Users/Mackey/Tools/emsdk-1.38/python/3.7.4-2_64bit/bin

Setting environment variables:
PATH = /Users/Mackey/Tools/emsdk-1.38:/Users/Mackey/Tools/emsdk-1.38/fastcomp/emscripten:/Users/Mackey/Tools/emsdk-1.38/node/12.18.1_64bit/bin:/Users/Mackey/Tools/emsdk-1.38/python/3.7.4-2_64bit/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
EMSDK = /Users/Mackey/Tools/emsdk-1.38
EM_CONFIG = /Users/Mackey/Tools/emsdk-1.38/.emscripten
EM_CACHE = /Users/Mackey/Tools/emsdk-1.38/fastcomp/emscripten/cache
EMSDK_NODE = /Users/Mackey/Tools/emsdk-1.38/node/12.18.1_64bit/bin/node
EMSDK_PYTHON = /Users/Mackey/Tools/emsdk-1.38/python/3.7.4-2_64bit/bin/python3
Mackeys-Mac-Pro:RecastJS mackey$ python make.py
  File "/Users/Mackey/Documents/Unity/Babylon Playground/Sources/Libraries/RecastJS/make.py", line 32
    print "ERROR: EMSCRIPTEN_ROOT environment variable (which should be equal to emscripten's root dir) not found"
          ^
SyntaxError: invalid syntax

Yo @Cedric … I spent the entire day trying to compile recast.js

Still get the error above about EMSCRIPTEN_ROOT

I tried: ./emsdk install sdk-1.38.33-64bit (NO LUCK)
i tried ./emsdk install sdk-1.37.40-64bit (NO LUCK)

I have python 3.9 installed globally

WHAT THE HECK COULD BE WRONG WITH BUILDING WITH: python make.py

continuing the discussion with DM …

YO @Cedric … Sorry to bother again tonight. But just need to know if you know of a way or is it possible to expose or add a IsAgentTraversingOffMeshLink type flag so we know when we are on an off mesh link… that way i can detect when we hit an off mesh like then rotate towards the end off mesh link position… What do you think ???

I can do it this coming week. until then, you can try to use getclosest location with the character position. if it’s too far from it, then you are off linking.

Thank you very much @Cedric

Crap … Yo @Cedric … Ran. into another issue while traversing off mesh links…

The get next waypoint does not update while traversing the off mesh link… It does not switch to the next waypoint till you complete the off mesh link… so you still stay facing the off mesh link START position and not the END position like what is desired.

So in addition to detecting if we are traversing an off mesh link, we need to get NEXT NEXT (or the one after the next) waypoint to rotate towards…

Or something like that … What do you think ???

Yo @Cedric … I have added these functions to my version of recastjs.cpp

// Mackey Kinard
int Crowd::getAgentState(int idx)
{
    const dtCrowdAgent* agent = m_crowd->getAgent(idx);
    return agent->state;
}

// Mackey Kinard
bool Crowd::overOffmeshConnection(int idx)
{
    const dtCrowdAgent* agent = m_crowd->getAgent(idx);
	const float triggerRadius = agent->params.radius * 2.25f;
	if (!agent->ncorners) return false;
	const bool offMeshConnection = (agent->cornerFlags[agent->ncorners-1] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ? true : false;
	if (offMeshConnection) {
		const float distSq = dtVdist2DSqr(agent->npos, &agent->cornerVerts[(agent->ncorners-1)*3]);
		if (distSq < triggerRadius * triggerRadius)
			return true;
	}
	return false;
}

The getAgentState function lets us check for DT_CROWDAGENT_STATE_OFFMESH to detect if we are traversing an off mesh link… Works great.

The overOffmeshConnection function will return true when we first pass over an off mesh link. Also works greats and only return true when you first hit the start off mesh link and not when we hit the end off mesh link. So its more of a off mesh link trigger. And also works great.

There is still an issue with getAgentNextTargetPath returning the start off mesh link position until it completely traverses off mesh link… So the player will rotate and look behind at the start off mesh link then correct when it finishes the off mesh traversing.

But the rest is look really good… Can you please add the getAgentState and overOffmeshConnection function to the agent as described above … Please :slight_smile:

Yep, It’s on my list. Will do it tomorrow! I think you can lock the orientation update when traversing an off mesh link.

I was able to everything I need to with just the getAgentState… basically rotation depends on velocity… so now when the state is offmesh , I simply calculate a new off mesh velocity by tracking last position. That seems to work pretty good :grinning:

1 Like

PR Helper function for off mesh link by CedricGuillemet · Pull Request #9151 · BabylonJS/Babylon.js · GitHub