Dynamically Translating/Rotating a NavMesh Surface/NavMesh Agent

Hi,

I am working on a space game, which requires AI characters to be able to walk on a spacecraft that is moving and rotating. Since Unity’s navmeshes could not previously do this, I implemented my own solution, which works ok. However, it’s quite crude, and so I decided to upgrade to Unity 5.6 and try out the new Navmesh upgrades.

I have added the NavMeshComponents from the Github page (GitHub - Unity-Technologies/NavMeshComponents: High Level API Components for Runtime NavMesh Building), and I have added a “NavMeshSurface” component to my spaceship object, which allows me to translate and rotate the spaceship object in real-time, and have the navmesh translate and rotate with it. So far, this all works great, I can see the navmesh moving and rotating as the spaceship moves.

The problem, however, is that the NavMesh Agent component on my AI character prevents the character from moving when the spaceship moves. The AI character is a child of the spaceship, so, with my system, I was able to just move the spaceship (By just modifying the transform and rotation values, I am not using a rigidbody), and all of the child objects (The player, AI, etc) would also move.

However the Unity NavMesh Agent prevents this, the AI ends up staying in place, while the ship moves.

Am I doing something wrong, or is this functionality not available with the Unity system? I would like to switch back to Unity’s navmesh if possible, since it is better than my system, but I need to be able to dynamically rotate and translate the parent object, and have the AI move with it.

Thanks for any advice!

I think I remember seeing that it’s not supported, basically saying that any movement is basically teleporting it and triggering recalcs galore… And I think that the navmesh agent’s destination is not actually updating with the rotation/translation of the mesh… so it could be that there simply is no path to that point in space. perhaps when you set a destination you should set as destination an empty gameobject that is a child of the space station as well so that it stays on the navmesh??? I dunno, I’m just thinking out loud. I think it could be terrible performance-wise if the agent could even keep up with the changing transforms…

Disclaimer: I’m far from an expert!!!

:smile: ok… but it gets a little bit hacky…

https://vimeo.com/214626131

So in the example scene #3 from the github (GitHub - Unity-Technologies/NavMeshComponents: High Level API Components for Runtime NavMesh Building) I added the oscillator script to the TiltedPlane and saw that pathfinding pretty much stopped as you described above… however When I added a LocalNavMeshBuilder to the TiltedPlane object it worked! But it only worked if I left the originally baked navmesh on there (actually an oversight on my part). If I had it as a navmeshsourcetag with the LocalNavmeshBuilder moving it crashed unity… it did eventually work but VERY jittery… the baked version was quite stable but would only work if the LocalNavmeshBuilder targeted the area.

I used Behavior Designer to slowly rotate the plane as well and then I have the yellow dude wandering with the red dude seeking after the yellow, also courtesy of Behavior designer… which is what you see in the video.

Soooo. try this… bake on your nav mesh, add the LocalNavmeshBuilder with your spaceship as the target, WITHOUT adding a NavMeshSourceTag… and report back. Good Luck!!!

Thank you very much, I’ll definitely try out those ideas and see how far I get!

I tried this out, and it didn’t seem to work.

What I did was:

Added a LocalNavMeshBuilder to the parent object (SpaceShip), set the “tracked” value to the spaceship, and change the size of the nav mesh builder. I also baked the navmesh surface.

The AI is still not moving with the navmesh.

The only other thing that I can think of is that the actual colliders are children of the SpaceShip gameobject, but this doesn’t make a difference for the navmesh, I can still see it and rotate/move it properly.

Do you have behaviour designer? I’ve got a scene I can share that has agents using nav mesh links to nav mesh surfaces on children objects as well. One issue I did notice is that agents will constantly try to reach their destination in global space, not necessarily the original local point on the nav mesh. In other words the destination doesn’t update with the nav mesh movements, so my thought is that when a destination is set it actually needs to be an empty gameobject or node that is childed to your space ship…

Also, gone is the need for the local nav mesh builder??? Not sure what changed for me but they are working fine now without it…

Also make sure you’ve got the latest scripts from the github

New video in action of the moving/rotating ‘spaceship’ with mostly stable pathing. There is the floor with two 90 degree walls each with it’s own navMeshSurface connected by two wide NavmeshLinks. The yellow is alternating between seeking the pink orbs and the red is following the yellow.

https://vimeo.com/214879562

From the github projects FAQ:

Q: Can I do moving NavMesh platforms?
A: No - new API is required for consistently moving platforms carrying agents.

Hi,

Thank you for your replies.

I haven’t tried to set the destination using an empty game object, I think that is a good idea, I’ll try that today.

I have the latest version of everything, I just downloaded the scripts a few days ago.

Jakob, I saw that on the github, but I figured I’d try it anyway, and it seems to work fine in the example scenes, which christougher posted, even if it’s not officially supported.

Is there a new API, or any updates coming that would add this feature officially? I would be prepared to wait for that, if it was forthcoming.

Thanks all!

Still no progress about this? :frowning:
I want to use NavMesh but I need floating origin… And it does not work here… Floating origin is a must for large world projects, we need to move everything (in my case when player are far than 999 units from the 0,0,0).

Yes, this is exactly what I am doing as well. It seems that there is still no built-in support for this, I have been evaluating other solutions (Both my own solution, and various options from the asset store) but it doesn’t look like anything fully supports this feature.

This is bad… It’s really hard making large real world-sized projects with Unity due to these limitations with its native features. Something amazing that could not be used… I’m trying to use them for pedestrians on a city, to put lots of them walking in random directions… In static scenes it works like a charm.

I hope that it will get fixed in a future release, this is a must for many projects.

If you find a good 3rd party dynamic navmesh that works with Floating Origin please let me know, I’m afraid of buying some on the Asset Store because I don’t know if they rely on global coordinates too (this research will take some weeks).

There is a recent thread about this on the a*pathfinding project pro forum

christougher, you won’t believe this, but that was actually me that wrote that thread! Look at the logo, it’s the same!

Marcos, you’re right, it would be awesome if Unity added translation/rotation ability to the standard navmesh, but from what I read, this would require huge changes to the actual API that the navmesh uses, and I suppose not enough people would use the new features for it to be justified.

I don’t know if unity 2018.1 has any navmesh improvements, I haven’t tried the beta yet.

The A* pathfinding project, as chris said, seems like it might fit the bill, I also tried out NavAI, which seems to work:

However it doesn’t seem to be maintained anymore, which is a big disappointment, because it showed promise.

1 Like

Did you manage to get this working, either using the A* pathfinding project or not? Wondering if it is worth me buying it or writing own A* for this. Need to know if it is fit for purpose (150+ moving units on platform)

1 Like

@Jakob_Unity Would one way to implement this ourselves be to have navmesh baked at origin, and then convert from local to world space position of the rendered components? This would allow say a moving pirate ship with pathfinding on it, while underneath what is actually happening is graph is not moving.

Asking because not being able to do pathfinding on moving surfaces is a very very big issue for me and I need some, any way, around it! So happy to try anything no matter how hacky

Daemonhahn, I haven’t purchased the A* pathfinding project yet, so I don’t know if it would work. However the developer of the A* pathfinding project did say that your suggestion is basically what his project does for moving/rotating platforms: IE, translate everything to the origin and back. So that seems like it could work, but it strikes me as a suboptimal solution.

Here is a quick video of the included local space demo (scene 13 from A* PP)…

https://vimeo.com/269009375

and here is the same scene modded with 196 agents with the local avoidance added even. Multithreading enabled for both the A* and RVO avoidance running about 45-60fps

https://vimeo.com/269015807

at a couple of points when the boat rotates as it turns the agents seem to get pushed to one side of the boat but that only happens with the avoidance enabled and that could probably be addressed as well… Either way this seems to have the functionality you’re after…

also Jakob_Unity hasn’t been sighted in months… :frowning:

This must be possible using in built navmesh!

I will try this weekend. I am thinking just using the navmesh for queries and doing my own avoidance and movement. Will post back with findings