#🤖┃ai-navigation
1 messages · Page 6 of 1
Ah no I meant the Physics.Raycast part
oh hmm
Seems like Navmesh.Raycast would be more reliable there
Although if your map is super simple it might not make much difference
I'd use the Navmesh one anyway
essentially what the raycast is trying to do is try to move the object further away back
but now i realize that if the terrain is curved, this wouldnt work
Yeah exactly
It does, that's the whole point
IIRC you should still snap it with SamplePosition afterwards
i assume hit.position is the actual position of the end point?
let's see
gonna have to check if the sampleposition even works
i think i know the issue, the terrain is very much elevated, but i'm setting the destination y to 0
i should project it onto the navmesh instead
is there a way to do so without using sampleposition?
actually i dont think i need to set the y to 0 or anything else at all
yup, that worked :D
hey i made a project that randomly generates an infinite backrooms like structure using gameObjects prefabs that i use as tiles. How can I get a dynamic navmesh without losing too much performance?
generate the navmesh for the tile, connect it to other tiles by generating navmesh links. do this gradually over time as to not overwhelm players computer
ok so the navmesh for the tile will be generated and be like in the prefab?
and the link at runtime?
cant i use a separate thread to generate the links?
yep that sounds most hardware efficient to me
wdym separate threads for links?
id imagine you’d be generating the links based off of code - as I don’t think the components connect navmesh surfaces together automatically
Well I imagine generating the links lags the game a bit
Also I checked and i cant do multithreading with that
Im probably gonna use Aron Granberg's A* Pathfinding Project
The free version of course
I hope it doesnt lack too many features
Any thoughts on how to get NavMeshSurface auto-generated links as bi-directional?
Feels silly that it's not supported by default
hey Everyone , in my game all my objects that are for environment I marked static , but still my navmesh agent is going through them somehow , how can i solve this
Have you baked?
Id really appreciate some help
when my agent switches to attack state it sometimes just kinda goes on a waddle off somewhere before finding its way to the player
i think its to do with these parameters is there an "ideal" set of values to set for really good tracking on the player and not so much worry about obstacles or something
is there a way to train ai to play any unity game?
This server is for people building stuff in Unity. Bot development, modding and player support for games made in Unity are out of the scope of this server.
Any suggestion to what type of server I should ask on?
why wont my navmesh go up these stairs. each individual step is smaller than the step high assigned and the collider for the steps (a slope) has a smaller angle than max. Ive even tried using modifier but they dont affect the navmesh at all
It was the mesh for some reason it works now
is there a way to make my agent not cut corners like this? or maybe make it more "robotic" in a way i guess?
Maybe not us a navmesh then? Just define waypoints and move the object between these waypoints.
Well, can anyone please suggest me a good behavior tree asset that is free? i can't use unity's behavior package because my project is on 2021.3, its really hard to upgrade at this point of my project.
Do what diltch said but if you want to use a navmesh try adding invisible objects as obstacles to prevent the ai from taking a abrupt turn or if you want to add a navmesh link and then your can choose how you want to interpolate between the points
Does anyone know a model i can use to identify two difference peoples voices, and then tell me, which person is talking into the mic on unity. been trying to figure this out using sentis, and importing models, but i just cant get it to work, and i cant find anyone who has done it before.
Hey guys I am able to bake the area , but the line renderer doesn't show the line
What can I do
You should provide a bit better explanation of the issue and it's context. Line renderer had no connection whatsoever to navigation by default.
Does someone know why the floor is all squiggly? My navigation works, properly despite this hiccup on the visual of the navmesh
I'm guessing it is probably the format of the collider that is a 3d shaped box that is too tall for these floor tiles
It looks like it's just really close to the floor so the rendering clips a bit between the floor and NavMesh. If so it's just a rendering issue, not impacting function.
Does it flicker if you move the camera?
This NavMesh Agents looks interesting for FPS games...
But what about side-scrolling games? Like platformers. Where enemies should drop down, or jump up to chase you. (Think of super smash bros maps)
How can this be implemented for that?
I managed to use it, but to make it jump to other areas... I use links, that makes them jump - differently than players - and i want to create bots that play very similar to humans. Guess its too much to ask lol
Honestly it sounds like the kind of problem I would solve without a NavMesh. NavMeshes are meant to find generic 2-dimensional paths on surfaces, but on a side-scroller, every surface is 1-dimensional.
But with platform links you're on the right track. You still want that element of pathfinding to determine which jumps to do to get from A to B. However I think a good approach here is to implement a node-graph system that contains platforms as nodes and jumpable gaps as edges. If you don't have hundreds+ platforms you can just throw in a naive Djikstra's search to find which path to take.
PS: Since you already seem to have it working with NavMesh you could extract the "path" information from the NavMeshAgent instead of re-implementing the above.
Either way, to make it work more "like a player" I think you would need some code to execute the jump properly, which is a bit of a physics challenge with calculating when to jump and with what running speed if that's variable. There are probably several ways to do this depending on how the jumps are done in the game.
"just throw in a naive Djikstra's search to find which path to take."
What is this Djikstra?
I played with NavMesh to see if it fits my levels. But there's an issue with logic im still thinking about.
And the answer may be to "drop breadcrumbs" behind the target object, so that it follows those (instead of the actual position)
Because this is a.scenario where it gets stuck
The player (cyan smiley) got in enemy (purple skull) target sight and got away to the right. And jumped in the platform above.
The enemy if it stayed behind, it tries to follow below the player - same X location, different Y.
If i could "leave breadcrumbs" from the player then enemy would know the player went to the red circle and then link to jump above and continue following.
And this is 2.5D game. Means you can move in X and Y. And there's also Z to "change lanes". Its a bit of a twist in my game.
If breadcrumbs works well enough for you then that's an okay solution. I think the original Unreal Tournament used "apples" to help their AI move around maps.
Djikstra is a basic type of path-finding algorithm. There is also A* (A-star) which is better but more complicated - and unneccesary for simple cases. So basically Djikstra searches for ways to get from A to B in a "node graph" (See screenshot) to find the shortest/quickest way to get there.
In your case, a "node graph" would just mean a list of platforms (node), where each platform has links (edge) to other platforms where it's possible to jump. In essence what Djikstra does (Simplified explanation) is to:
- Start at the current platform (of the enemy)
- Check all links from current platform to other platforms
- Check if any of them is the "goal" (The platform where the player is)
- (Djikstra would prioritize the ones that are closest first)
- Otherwise, repeat this process but pretend the enemy starts on the neighbor platforms this time. (And skip the original platform, no need to go back and forth)
So each "repeat" expands the search to the next platforms. And when it finds the player, then it should report what platforms it searched to in order to get there. And now you can make the enemy start moving in that direction.
(If you don't care about which path is the "shortest" then a "Breadth-First-Search" is simpler yet to put in code)
So here's an illustration for how the process would be (Enemy is red star, tries to reach player who is green star):
- Breadth-First Search will first check if the first jumps (Burgundy colored lines) will reach the player. If not, check if secondary (orange) jumps reach the player. If not, check if third jumps (Red lines) reach the player, and so on.
- Djikstra's would also check how far the enemey has to move for each jump and always check the shortest options first. For example a long platform could take more time to walk than doing 3 jumps on another route.
If this sounds overly complicated you can explore other options, but both of these should be easy to google and find example code for. Specially the BFS code is probably just a dozen lines long as long if you have the platforms/links configured (which makes out "the graph" in this case)
I have a big problem with navmesh agent unity. I have used nav mesh agent in my 2d game to move characters. The problem is when the destination is not in nav mesh (it is in a hole navcut), they can find a valid path and move to it! I have checked the characters' nav mesh agent. The property auto traverse off mesh link is unticked, also, the jump area mask has not been included in the layer mask. What is the problem?
In editor, I see red dot lines from the character to the target in the hole
Oh i love this! I believe another name for this is Waypoints. And this is definitely what i wanted to implement... Dont have C# knowledge for that, and AI couldnt help lol and couldnt find a platformer waypoint asset for that.
But this is the best solution because my game will have capture flag / invade or defend base.
So enemies when they are not chasing a player, they will go to the other side of the map for the objectives.
Waypoint when following player
Waypoints to get to the other side
So these are called Node Graph?
Wondering how to use visual script for this hmm 🤓
Yeah if waypoints are linked then you essentially have a node graph - correct.
camera doesn't flicker, altough, I programmed the camera myself, so maybe it would otherwise? not sure
the view of my game is orthogonal, top down, if that makes a differenece
No worries, it's just if it just looks bad because there are two overlapping meshes (floor tile and nav mesh) then typically that causes the rendering engine to not know which one should be visbile on top of the other, and you get flickering.
But if the mesh works and you're able to walk on the entire surface, whether it's blue or white, then it's safe to assume it's just visual.
I might also add that I had issues with using NavMesh on "Quad" meshes in the past, while both "Cube" and "Terrain" meshes work fine. Not sure if that's related.
Maybe it is fine for now. My floor are tiles, and they are prefabs, with a Cube collider. although, the cube collider goes above the floor. I might want to change this..... I'm almost sure this one wil bite me sooner or later.
No, you cannot set the NavMesh Agent radius to zero in Unity, as the minimum allowed value is 0.05f.
Why? What is the reason for that? With zero radius, nav mesh will be simpler and less polygons
Hello, I am trying to modify a path of my agent by changing corners positions. In debug and visualization the points are changed correctly, they retain their Z coordinate (I am working in XY plane with NavMeshPlus on top of built-in NavMesh) and they all lie on the NavMesh. Then I try to run agent.SetPath(newPath) which returns true. The newPath as I said is set up correctly, I do double check it and yes it is modified. But the agent's path remains untouched like nothing happened. I tried temporarily disabling/stopping the agent, I checked paths million times visually, through VS debug and console. I spend hours googling it but only found one unsolved post with the same issue. Is it not possible to set your own path despite having SetPath function?
Hi, what is the correct way to do if I moved the racking, how do I recalculate the path or will it be expensive?
search up “navmesh surface component” and you should find all the info you need
What system could be used to make enemies dynamically clear an area without predefined patrol points?
What's does "clearing an area" imply in this context?
Well, I would think it means to look for enemies and not keep looking for enemies in places you've already checked
Well, then you'll need to implement this "look for enemies" logic, that could be implemented in many different ways, and isn't necessarily related to navmesh.
In the simplest form, you could just loop all the enemies on the map, get the closest one and tell the agent to move somewhere around that position.
Or even simpler, just let it move to a random position on a map. That's gonna be chaotic, but might satisfy your needs.
If you don't have waypoints, you need some other way to provide the agent with a target destination. As for what way exactly, it's entirely up to you and your project.
this is how it's currently done as a placeholder
I dunno where I was going with this. I can't really think of a way to get an AI to find "rooms" to clear without manually marking them.
There exists a navmesh, that's pretty much all you're working with
Exactly. The ai would only do what you tell it to do. You need some algorithm or way to identify the rooms. Usually that's done manually by placing waypoints. If your rooms are prefabs, you could place the waypoints in each of the prefabs, so that you don't need to do it for each level that combines the rooms.
If you generate the level procedurally, perhaps there is some logic that identifies rooms in it. You could use that info to place markers or something.
Not procedural
The idea here is that the enemies clear rooms like in real. You know, checking the corners, etc
All I can think of is placing clear markers parented under designated rooms that the AI will have to go through in order to clear it well
Yep, that's pretty much how it's done normally. With the generative ai advancing it might be possible to do it in a more "humanly" manner, but it might be too much for a game.
Generative AI running a background algo for every enemy in the game 😆
Jesus. I'll just mark the rooms. Thanks
I need help with the technical part of my AI. So how do they actually move? Right now I have a character controller setup and WASD/Mouse control.
Say I mark a point on the nav mesh for him to go to. I don't quite understand how that translates into the same control as you would have with a mouse and keyboard
I dunno, this is a pretty silly question. But I see games like Tarkov where the AI is basically just players posessed by an FSM - they look around, sprint, move in nonlinear ways, etc
Many games that require more control over the ai usually use the navmesh only as a pathfinding tool, and implement their own controllers for ai(as opposed to just using the navmesh agent as is).
For example, generating a path via the navmesh, but moving the character along it manually by adding forces or applying velocity
hi, i'm wondering with the ai navigation stuff in U6, is it possible to have something like automatic map recognition?
(sorry bad explanation lmao)
like if i had randomised map layouts, would it be possible for it to recognise it without any issues or would i have to make my own map recognition?
You can bake the navmesh at runtime I think.
Ahh thank you. I will try this
my ai boss is spinning around like a bey-blade half the time, the other half he is falling through the floor, i use a navmesh agent which is a child component of his, aswell as a character controller and a rigid body , none of my other ai characters act like this, only him - any insight is greatly appreciated
why is my agent getting permanently stuck on this corner? it seems to be trying to go right and left simultaneously and is getting stuck
why doesnt it follow the path normally?
Does it have a path?
im not too sure what you mean by this. it has a target and behaves normally everywhere else, but it gets stuck on this staircase area for whatever reason
if the target for this agent is standing close to it, it will be normal
Like, can you visualize the path that it's following?
yeah the path keeps alternating every other frame
oh actually its a problem with my code, never mind 😅
Hey, I'm kinda confused, Why does the Nav Mesh Agent makes an collision outline that goes below the ground?
It was just a matter of centering the character in the Character Controller! nevermind
is there any way to have navmesh agents take indirect paths to their targets? I have these really simple test enemies i'm working on, but right now they just beeline it to the player which is kinda boring https://streamable.com/9qx5yl
I want them to be able to surround the player in a group, or find points to kinda "hang back" from while other enemies attack the player, stuff like that
Not with just the navmesh. The purpose of navigation systems like navmesh is to find the shortest path to the target position.
If you need anything extra, it's up to you to implement it.
This sounds like a combo of some group ai and maybe flocking behavior.
yeah I know, i was just wondering about ways to modify the straight path the navmesh gives you but I was just lacking creativity lol
exreme example with not much actual coordination but it's already nice just to add some random noise to the movement https://streamable.com/21zd3n
is there a way to override the agent rotation? i want to make movement and look direction of an npc independent on certain moments (like a strafe behaviour), and for now i'm just using LookAt to override the whole gameObject rotation to look at my target, so i was wondering if it's possible to do something similar without altering the Transform directly
You can disable updateRotation property on the agent.
Or whatever it was called
I'll try to do that, if not i think setting the angulrSpeed to 0 could also work
i think that’d make the agent itself stop rotating, updateRotation just stops the object from matching the agent’s rotation
my navmesh isnt baking and sources say 0
why is this selection greyed out? what does that mean?
im using navmeshplus and it's giving me an error NullReferenceException: Object reference not set to an instance of an object
UnityEngine.AI.NavMeshSurface2d.CalculateGridWorldBounds (UnityEngine.Matrix4x4 worldToLocal) (at Assets/NavMeshPlus-/NavMeshComponents/Scripts/NavMeshSurface2d.cs:487)
UnityEngine.AI.NavMeshSurface2d.CalculateWorldBounds (System.Collections.Generic.List`1[T] sources) (at Assets/NavMeshPlus-/NavMeshComponents/Scripts/NavMeshSurface2d.cs:448)
UnityEngine.AI.NavMeshSurface2d.UpdateNavMesh (UnityEngine.AI.NavMeshData data) (at Assets/NavMeshPlus-/NavMeshComponents/Scripts/NavMeshSurface2d.cs:233)
UnityEditor.AI.NavMeshAssetManager2d.StartBakingSurfaces (UnityEngine.Object[] surfaces) (at Assets/NavMeshPlus-/NavMeshComponents/Editor/NavMeshAssetManager2d.cs:124)
UnityEditor.AI.NavMeshSurfaceEditor2d.OnInspectorGUI () (at Assets/NavMeshPlus-/NavMeshComponents/Editor/NavMeshSurfaceEditor2d.cs:295)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass79_0.
hello?
Are you on the latest version of NavMeshPlus for your Unity version?
There is no "NavMeshSurface2d", It was removed few month ago.
h8man on Apr 24, 2023
i reverted to a previous version of navmeshplus
is it not compatible with unity anymore or something
You are getting errors from a class that apparently hasn't existed for several years. What version of NavMeshPlus are you on?
i see
i just found it in a post somewhere online
so i should use navmeshsurface
instead of 2d
is it possible to manually modify NavMesh Triangulation via code?
You mean the mesh generation? I don't think so, unless you have access to the engine source code.
i cant see my navmesh
it should be blue
i tried rotating xy
and not rotating
and also it says sources 0
i have 4 navmesh agents
all static
hellooooo
how do i make an ai agent takepaths that are not visible to my player?(if such a path is available)
(using simple raycasts to check visibility)
i want my agents to hide, but in the process of moving to a hidden location sometimes they take paths that go right in front of the player which defeats the whole purpose 😔
You can make your visibility zone as obstacle
my navmesh surface isnt showing the blue area after i try to bake
and it says sources 0
Hey all. I'm in the middle of a game jam and am running out of time, but I ran into the bug with some nav mesh agents. I have them patrolling right now, but they're generating weird paths to get to certain points:
there aren't obstacles in the way, the nav mesh is a flat surface. Any idea what could be causing it?
show navmesh surface gizmos/blue + anything relevant, like code and inspector for agent
/*Checks if the robot is in attack distance.
If it is, the robot stops
If it is not, it checks to see if it has a path towards the player
if it does, it moves toward the player
if it does not, it stops chasing and returns to it's marching path*/
if (distanceFromPlayer < AttackDistance)
{
agent.isStopped = true;
stateManager.attacked = true;
}
else
{
agent.isStopped = false;
if (!agent.hasPath && calculatePath)
{
cameraAlerted = false;
calculatePath = false;
spottedPlayer = false;
agent.destination = marchTarget.position;
}
else
{
if (drone)
agent.destination = new(target.position.x, transform.position.y, target.position.z);
else
agent.destination = target.position;
calculatePath = true;
}
}
}
else if(spottedPlayer)
{
framesBlindedFor++;
}
else
{
framesBlindedFor = 0;
agent.destination = marchTarget.position;
}```
if (transform.position == marchTarget.position)
{
if (currentMarchNum == marchingOrders.wayPointTransform.Length -1)
currentMarchNum = 0;
else
currentMarchNum++;
marchTarget = marchingOrders.wayPointTransform[currentMarchNum];
}```
inspector for the agent
also would play around with stopping distance and use. <= for distance check rather than == , a bit more room to work with than approximate to 0
would up the acceleration and rotation speed too
Hey
I have this issue. My nav agent radius is quite thin, and he constantly hugs the corners of walls
Every time the nav tries to wrap around a tight edge, it snags him and slows down
How can I make the movement more natural, in that it prefers to go to the middle of whatever doorway/hallway its in?
I am not using the navmeshagent's movement and overriding it with CharacterController,
I don't want to just increase the radius of the agent because that will prevent him from being able to access certain areas
my navmesh wont show in 2d mobile projects
after i bake
it works in other types of projects
yo im getting some errors on the end of my training run in mlagents its telling me i dont have the oxxn model installed even tho i have it installed
im not sure if this is a version error like wrong unity verson or python or if i just have it wrongly installed
everything else works just i cant get the ai brain model
Is there a way to just assign a section of a navmesh to a different area mask? e.g. if I've got a cylinder that intersects the navmesh, can I just get that intersection and change the area mask? I've got a building system where the placed blueprints should be passable and not part of the navmesh, but builders shouldn't stand inside of what they're working on.
If not I guess I could just procedurally generate "work sites" based on the mesh for the object being constructed and have workers stand in those lmao, that's probably simpler in terms of execution
Why do my navmesh corners generate 0.08m above the surface they're baked on?
I can even see that the surface has an offset. This is bad. I do not want this.
I saw online that clicking Build heightmesh fixes this, but it does not
I am not using NavMeshAgent. I am calculating the path with NavMesh.CalculatePath
Im not a pro AT ALL in ai navigation
But why not use navmeshagent?
Just soved an annoying problem, and I thought I'd briefly share...
I'm using NavMesh.CalculatePath to compute paths in my map
I (incorrectly) assumed that the default agent type's ID was 0
so I did this
new NavMeshQueryFilter {
areaMask = NavMesh.AllAreas,
agentID = 0
}
The result: area cost was ignored!
It still found a valid path, but the path was suboptimal
I thought I was having problems with nav mesh links at first, but then I discovered it was always pathing wrongly
hello, i've got an AI agent which for some reason doesnt reach certain points when for example too far away, it just returns an incomplete path:
private bool TrySetDestination(Vector3 worldPos, float sampleRadius = 3f)
{
var _reusablePath = new NavMeshPath();
if (!NavMesh.SamplePosition(worldPos, out var hit, sampleRadius, NavMesh.AllAreas))
{
Debug.LogWarning($"Given path is not reachable to: {worldPos} due to sample not reached!");
return false;
}
if (!agent.CalculatePath(hit.position, _reusablePath) /*||
_reusablePath.status != NavMeshPathStatus.PathComplete*/)
{
Debug.LogWarning($"Given path is not reachable to: {worldPos} due to path not being complete, {hit.position}");
return false;
}
agent.SetPath(_reusablePath);
return true;
}
most of the time it returns Given path is not reachable to: {worldPos} due to path not being complete
this is the map the agent has to move on
i've made sure every area is reachable
and in fact it is
but for some reason when then specified point to reach is far away it simply returns an incomplete path
may i know if this is bug with unity or am i doing smth wrong?
The movement provided by NavMeshAgent is pretty basic and not really customizable.
oh alright
Hello, I've been working on my game, and I'm working on a state machine for my killer AI in my game, but I just feel like it's weird and clunky and I don't really know what I'm doing, can anyone help?
You'll need to ask a specific question
Sorry, I’m just trying to perfect it, I’m making an idle, patrol, chase, and attack state, and I’m just not the best at AI in Unity
Can you have multiple pathfinder objects in a scene
If you mean NavMeshAgents, most certainly you can
Hi, guys! My agent works bad on some surfaces and i cant figure out what is a problem. These surfaces seems to be the same and i even swapped it but some agents seems to be lagging no matter of a surface. I thought, maybe the problem is in objects around, but i deleted it all and nothing changed.
Code is pretty simple:
if (playerTrackerScript.targetPlayer && playerTrackerScript.targetLocked && playerTrackerScript.distanceToTargetPlayer > 2f)
{
if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
{
agent.SetDestination(playerTrackerScript.targetPlayer.position);
}
}
The code is rinning in Update. However, if i set destination only once, it seems better, but i need to update it in order enemy to follow the player.
Is there a way how to incentivise the AI to walk through a normal path aka like in the middle and not the corners. Cuase my enemy keeps on getting stuck on corners cause he's sticking to the wall instead of using normal pathways
However, if i set destination only once, it seems better, but i need to update it in order enemy to follow the player
you can set it every some time (like a few times a second instead of every frame) or when the player goes away from the destination (distance between player and destination is above some threshold)
how do i increase the white outline
i want the non walkable part to be more like this, how do i achieve that?
increase the agent radius
Hey,
How can I make the interior be accessible by the AI please ? Like it's seperated from the main part of the navmesh because of the Text so I don't know how to make Unity understand that the text shouldn't interfere with the patfinding 😬
you could switch navmeshsurface from collecting objects renderers, and instead use colliders
When I do that all my navmesh disappear
do you have colliders setup ?
Colliders for what ?
the floor, the walls etc.
I'm using the Voxel Plugin which handles that automatically at runtime, here the issue is regarding my gameobjects that have a text child, for some reason it's considered by the navmesh while it's supposed not
Asssuming you're unity 6+, I think there was a component to exclude objects from the navmesh building process. Or on the contrary add specific objects only. Might want to look at the docs.
Here are all the things
But that's in script, isn't it ?
No. It's a component
But it's asking for an "agent", does that mean I should make those texts have an agent component ? 🤔
You must be looking at the old docs. unit 6+ don't even have that section. They have a reference to the package docs
Wdym? If you look to the left on my screenshot you'll see that this page is for NavMesh Modifier component.
I'm not even looking at the doc, I'm looking in the editor
Yes, you need to specify what agents it should affect. The documentation explains it all.
So that means I should add an "agent" component to my "texts" objects ?
Thank you 👍
I'm working on a racing game and I want to have AI Drivers but when I give the the different points to go to they're picking the shortest path possible and cramming together how can I make the driving feel natural
I have this race track each piece has a navmesh surface script with walkable selected, a box collider and they are static. They are custom meshes but when I bake them they don't create a surface to move the AI on
It seems like my blender meshes can't receive the surface
Could blackboard listen to events coming from a ScriptableObject or a C# script please ? If yes, how please ?
wait I found how this new system works
SOLVED by ownRotation script.
Hello, does anyone here have experience with A* pathfinding project PRO version?
I don't know why but it behaves differently for me compared to gameView and when I have split scene/gameView ... once I have split everything works correctly, but as soon as I click cleanly into Game view, my enemy either doesn't rotate or rotates badly, I really don't know. I can't deal with it anymore. Using richAI + Seeker
attached video -> https://ctrlv.tv/VuXv
why is my navmesh like that
I'm making a patrol system for this enemy and I've put a series of patrol points and it goes correctly towards them and everything is going well but I don't know why sometimes it gets stuck in the middle of the route, I have the transitions fine, all the decoration seen in the image has the Navmes Obstacle and the walls are static, they have static activated, I don't know why sometimes he gets stuck and doesn't know what to do. I'm using a ghost that the enemy follows so the movements are more natural.
Debug
This is solved now
Use logging and visual debugs as well as info in the inspector or the ide debugger.
it was nonsense
But thanks
I had forgotten to activate a thing in the inspector hahaha
Hey everyone,
I've tried search and the last answer was in 2023 LOL
Does anyone know if "NavMeshBuilder.UpdateNavMeshDataAsync" is broken or has any known issue?
I've asked in the Untiy Discussion and no answer from any staff or anyone. I have a script that is supposed to bake only part of my navmesh (through bounds and navmesh data), but it does not seem to work.
Even worse, if I use it, it erases my navmesh data in realtime. The only option is to keep using "async" with (example) "navMeshSurface.UpdateNavMesh(_navMeshSurface.navMeshData);" which is not really good, because it syncs the whole scene.
Thanks in advance.
Hi all
I'm working on an endless runner game (fast paced) and I want to add some enemies using Navmesh. The game is player position based (the player moves and the world segment spawn accordingly). So I want to know that if there any better way to bake Navmesh surface for better performance on mobile? Please help me
This doesn't sound related to navigation. #1202574086115557446 is the appropriate channel. Make sure to provide more details, as it's not clear what kind of model you're using and what you mean by "give a list of valid words"
anyone worked with large open world? If so then how you resolved large map navmesh?
im doing isometric game btw. As in 3D isometric terrain
anyway just normal game map
but being split into chunks or something
reattaching them even for seamless pathing
one thing to note i am not using agent for movement
doing NavMesh.Calculate with a lot of custom behavior
Hello, I have a question on ML agents, as I am starting out i want to know if certain things are possible.
I want to train an AI live with the player (everytime the AI dies it learns to respond to player actions) but im afraid it takes too long, so I decided to simulate a player and have that bot train my AI over a longer period of time.
Question part: I was planning to save policies of the training every few episodes and use those as a "rank-up" system where everytime the AI is reinstated it will progress to the next "better trained" policy.
Actual Question: Does Unity ML-Agents allow me to save the training values every x episodes?
This channel is for navigation related questions. For everything else there is #1202574086115557446
im using nav mesh where the agent runs away from the cat but it always gets stuck in the corner, how do i make it so it goes along the wall?
You need to provide more details. And also fix the problems in console
this is the code the agent uses:
using UnityEngine;
using UnityEngine.AI;
public class newNavScript : MonoBehaviour
{
public Transform player;
public float fleeDistance = 5f;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
Vector3 directionAway = transform.position - player.position;
Vector3 fleeTarget = transform.position + directionAway.normalized * fleeDistance;
NavMeshHit hit;
if (NavMesh.SamplePosition(fleeTarget, out hit, 5f, NavMesh.AllAreas))
{
agent.SetDestination(hit.position);
}
}
}
but when it runs into a corner, it gets stuck
if you could give me the answer, that would be helpful. thanks
You're directing it to the to the opposite direction of the cat, so theres no where else to go after it hits a dead end (like the corner) unless you redirect again.
You're gonna have to have some sort of corner checking logic, there are multiple ways to do that so it depends on what you want
i want him to run across either the left or right wall. i tried but wasnt successful. all i did was make him alternate from cat to wall continuously
What did you try
i tried so many things in code. i cant remember
i tried to make him avoid the wall and the cat at the same time
but it just alternates
I have an idea, ill do it in Unity to see if it works and then ill tell you
ok thanks.
This problem seems to be harder than I initially thought
Yeah me too lol.
So I tried corner checking and so on, the problem is that it will just keep going along the walls.
You're gonna need some smarter AI, not one that just blindly goes in the opposite the direction, because this will cause it to go the borders of any map unless the player specifically guides it away @simple ravine
Yeah. Thanks for helping anyways
if anyone else has the answer, pls help!
hi how can i learn basic ai navigation for 2d
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
for 2d
Google then. There are tutorials online.
You will need to use a third party asset, like the A* project.
I would consider having a pathfinding goal towards one of many predefined points on a map and layering avoidance on top of it.
You can use this sort of logic to combine the goals of moving to that map point and avoiding danger.
avoidanceMovement = directionAwayFromDanger * dangerAvoidanceWeight * (1f - distanceToDanger / distanceToBeginDangerAvoidance)
finalMovement = navigationMovement + avoidanceMovement```
im in Unity 6 HDRP, trying to reference a NavMeshSurface component, which apparently requires:
using UnityEngine.AI.Navigation;
but that isnt found, anyone know what it needs to be?
NVM, VS was being silly
yo so im trying to put a navmeshsurface on a tilemap but failing to do so (I think because tilemap is not mesh) so i tried to put colliders and use physics colliders instead of render meshes but that doesnt work either. Could someone help and tell me if its possible to find a solution? Thank you. I am intending the floor tilemap to be walkable and the wall one to not be but its not working for either. The blue map thing doesnt show. Any help would be appreciated thanks
Oh and ita version 2021.3.something the one with long term support
Navmesh doesn't work in 2d. It doesn't work with 2d colliders, and your tilemap is likely in the XY plane, while the navmesh should be in xz.
You'll need to look up alternative solutions for navigation in 2d.
Oh thank you
do you have any ideas
I just sort of want the enemy to follow the player without banging into a wall
I think there's a 2d navmesh project on GitHub, as well as A* project that is very popular for 2d games. Aside from that, google.
ok thank you
hi, I've been experimenting with behaviourtrees. after changing something in one of my action scripts this happened in the BT viewport view:
I can no longer see any of the nodes incl. start node
but the nodes must still be there somewhere because the behaviour tree still works during runtime
I also get this error when the BT window is open:
NullReferenceException: Object reference not set to an instance of an object Unity.Behavior.ReflectionElement+<>c.<CreateFields>b__5_0 (System.String variableName, Unity.Behavior.GraphFramework.SerializableType type) (at ./Library/PackageCache/com.unity.behavior/Authoring/UI/AssetEditor/Nodes/ReflectionElement.cs:50)
I can't create any new nodes
additionally, I tried reverting back to before I made the change that caused this in my version control but the issue persists
I think this was because I tried changing the action story via script... note to self, set it in the inspector otherwise it irreversibly corrupts the entire BT
hi 🙂
any idea why that just wont work?
i use the default bake for it.
it consists of 3 gameobject, all static, all have a box collidor.
They stand out too much, making it think that it's a separate surface. And they probably don't have enough surface area to have their own navmesh surface.
What is a Good Solution?
Change the navmesh settings(step height), or lower the object so that it's surface is on the same level as the rest of the ground, or exclude the object from the bake.
trying to make a pacman ghost entity, where it snaps to rotate around the maze. But it slows down on every corner it reaches even with angular velocity maxed and stopping distance turned off. Should i manually code the rotation? is this a common problem with navmeshes?
is there a built in setting to make a NavMeshAgent only finish the path if its looking at the path target location?
So lets say its 1 unit away from the path, with a stopping distance of 2 units, but the end point is behind it, so it'll move to rotate regardless of its stopping distance so it looks at it as well
if not, what would be an effective way to do it?
Not. Move the object along the path manually and implement your own stopping logic.
Hi gang I remember looking into this 2/3 years ago and there wasn't anything amazing but if I were to use navmesh agents in an rts style game where players can say... place buildings that need to be pathed around what's the best way to go about this?
I think I remember some extra package that meant you can regenerate the navmesh at runtime is this still a good option?
navmesh obstacles with "carve" enabled regenerate the navmesh in realtime :)
that seems awfully simple and I'm very confused why I didn't find this when I tried it before
even made a forum post
Hello. I use NavMeshAgent + Root Motion to move it with animation. I change the position of the object, but this means that it won't collide with the environment and with other agents. What should I do?
having a painful issue with BehaviourGraphs and Navigation where the Behaviour logic just gets... stuck, seemingly randomly
pictured is the behaviour logic, its currently evaluating the branch as false, which according to my understanding, means that the tree should just restart since the node terminates that branch
and it does do that as expected but sometimes it just hangs here for seemingly no reason
also, the navmeshagent just stops moving when this happens even though it currently has a valid target position
like the entire prefab just freezes or something
I've just remade the behaviour graph thinking it was my logic but it still happens even though there's no issue with the logic at all
very frustrating
what up so i have an issue right here, why is the orange target thingy showing to that location?
that cube thing should go to the player
player is the red capsule
nvm i solved it somehow lol
Heyo!
I'm trying to implement a pawn system kind of similar to how unreal handles PlayerControllers, Pawns and AIControllers in order to have a shared movement set between players and AI. So I need to kind of "extract" the path from a NavMeshAgent.
Vector3 desiredVelocity = navMeshAgent.desiredVelocity;
Vector3 normalizedDirection = new Vector3(desiredVelocity.x, 0f, desiredVelocity.z).normalized;
CurrentPawn.ReceiveInput(new MovePawn
{
Direction = new Vector2(normalizedDirection.x, normalizedDirection.z)
});
Currently I'm setting the NavMeshAgents updatePosition and updateRotation to false and only using it to get a path to follow, which I then extract using the desiredVelocity, it works perfectly fine and the AI follows the target as it should but it seems to be ignoring the obstacle avoidance radius causing it to get stuck on edges and sides of objects. I've considered using the static NavMesh.CalculatePath but would really like to keep the Unity built in path-smoothing and obstacle avoidance if possible. Does anyone know of a way I could cause the NavMesh path to still avoid other agents and obstacles while not strictly using the Agent?
I am watching a youtube Unity AI Navigation Basics tutorial. They are talking about AI 2.0 Navigation samples but I can't seem to find them.
Hi! Can anyone help me? My agent have agent.autoTraverseOffMeshLink = false;
When he touches nav mesh link, he stucks on it. If i reset path, put another destination or try to warp him out of offmeshlink, he buggs and not moving.
Why this happening, anyone?
All of my AI Gizmos such as NavMeshLinks, NavMeshObstacles and NavMeshSurfaces are Super Transparent and barely visible. How can i change the Transparency of those gizmos?
hey guys, I am on Unity 6 and i am having issues with navmesh navigation. I have a script which makes navmesh in runtime since I am using procedural generation, it fully works in the editor but when I try to build it does not bake properly, giving my agents an error. Does anyone know why this is the case? I've never encountered an issue where something works in editor but not in build
For context I am using Unity 6 and here is my runtime baking code:
using UnityEngine.AI;
using Unity.AI.Navigation;
using System.Collections;
using Mirror;
public class RuntimeNavMeshBaker : MonoBehaviour
{
[Header("NavMesh Surface")]
[SerializeField]
[Tooltip("Reference to the NavMeshSurface component.")]
private NavMeshSurface navMeshSurface;
[Header("NavMesh Baking Settings")]
[SerializeField]
[Tooltip("Time in seconds to wait after dungeon generation before baking the NavMesh on the server.")]
private float waitSeconds = 2.0f; // Default delay for server
/// <summary>
/// Public method to initiate NavMesh baking.
/// For clients, waits until the expected number of dungeon objects are spawned.
/// For server, uses a fixed delay.
/// </summary>
public void BakeNavMeshAtRuntime(int expectedObjects = -1)
{
if (navMeshSurface == null)
{
Debug.LogWarning("[RuntimeNavMeshBaker] NavMeshSurface reference is missing!");
return;
}
StartCoroutine(BakeNavMeshWithDelay(expectedObjects));
}
/// <summary>
/// Coroutine that handles the delay or waiting condition before baking the NavMesh.
/// </summary>
/// <param name="expectedObjects">Number of dungeon objects to wait for on clients. -1 for server.</param>
/// <returns>IEnumerator for coroutine.</returns>
private IEnumerator BakeNavMeshWithDelay(int expectedObjects)
{
if (expectedObjects > 0) // For clients
{
Debug.Log($"[RuntimeNavMeshBaker] Waiting for {expectedObjects} dungeon objects to be spawned...");
float startTime = Time.time;
float maxWaitTime = 10f; // Maximum wait time in seconds
while (GameObject.FindGameObjectsWithTag("DungeonObject").Length < expectedObjects)
{
if (Time.time - startTime > maxWaitTime)
{
Debug.LogWarning("[RuntimeNavMeshBaker] Timeout waiting for dungeon objects, baking anyway.");
break;
}
yield return null;
}
Debug.Log("[RuntimeNavMeshBaker] All dungeon objects spawned or timeout reached, proceeding to bake.");
}
else // For server
{
Debug.Log($"[RuntimeNavMeshBaker] Waiting for {waitSeconds} seconds before baking NavMesh...");
yield return new WaitForSeconds(waitSeconds);
}
// Proceed to build the NavMesh
navMeshSurface.BuildNavMesh();
Debug.Log("NavMesh baked successfully at runtime after delay.");
}
}```
When I added a navmeshsurface to this and baked it it would set the walkable paths to the windows and other stuff and not the actually floor itself. I tried adding navmeshmodifiers and it still wouldnt do anything.
@everyone Hi! I was wondering how AI can be used when making a game in Unity. I feel like ChatGPT doesn't work that well for it. Does anyone have any suggestions?
Can anyone help with this
That's interesting. What Unity version is that?
2022.2. Something i have forgot
Could be wrong, but I think that's the version where they transitioned to the dedicated navigation package with navmesh surface components.
Might be worth checking that.
Ok
How good is the behaviour package of unity to make ai?
I used to code ai by getting the navmesh agent component attached to npc and calling the set destination function in scripts
Also can the animator be used for ai? It is a state machine I know that much, but can I attach ai related code to individual states, is that the intended use or am I doing it wrong?
That is the navigation part and you'll keep using it (or some equivalent) regardless of what high level decision making pattern you end up using.
Technically yes, but it is specialized for animation. It's a heavy solution for a basic state machine and a step down feature wise from something like the behaviour package.
Is there a way to see exactly what is and isn't walkable? i'm getting some super weird pathing where it completely ignores some obstacles and not others using navmesh and also if some land is walkable but has an obstacle on top of it it should avoid the land anyway right?
Like it completely ignores obstacles and just jumps on top of them
When you bake navmesh it shows the area walkable as blue
That wasn't happening sadly is there something I need to turn on for that to happen?
hey, a question: I set the destination for agent, and the remaining distance is e.g. 2, which is correct (according to my intentions at least 😄 ) but in the very next frame that remaining distance is 0, agent is not moving (and everything falls apart). Also, stopping distance for the agent is (currently) set to 1. Any ideas why would agent stop moving in the next frame?
Did you try enabling the agent gizmos and having a look at them? It could be that the agent actually did move, but something is fighting it for setting the object position.
no the agent did not move, I know since I record desired position in separate variable and I can confirm that it is the same as agent.destionation at the beginning. Also, if something is changing agent destination it is not my code, I triple checked 🙂 but something does change it, since it is different and remaining destination becomes zero
am I blind and just missing the shading? this is with navmesh baked
Not entirely sure what you mean. Agent.destination wouldn't tell you anything about whether your agent moved or not. And it's definitely unrelated to your code. Agents move automatically every frame.
What I'm asking is whether there's a disconnect between the agent's internal position and that of your gameobject.
Seems like no navmesh is present. Or maybe you have it disabled in the gizmos.
the agent is setting my gameobj position, so no, there is no disconnect between those 2 since I never update go position myslef. It is simply (or rather "simply") that agent gives up on moving to designated position....
That's not how it works. The agent has an internal position that it calculates and updates. It tries to apply it to the transform every frame, but if there's another system that does that, they will fight each other.
yes yes, you are right and I know that, but I am telling you that there is no other system that sets position of my object (except at spawn time, but this happens much later)
The fact that the remaining distance changes, hints that the internal position might be updated correctly, and it's exactly applying it to the transform that is the issue.
You need to confirm that by looking at the agent gizmos.
well... I can't see much from the gizmos, since this happens in 2 frames time... and when it's all over gizmos look "correct". And for some reason the "step" button does not work, so I can only use breakpoints, but that does not help with looking at gizmos...
When it's all over, what do you see exactly?
Can you take a screenshot of before and after these few frames? With the gizmos visible.
ok so, I set the agent destination in frame 1, in frame 2 it seems correct from breakpoint view. then in frame 3, remaining distance is 0, agent destination is the go position from frame 1, and agent is not moving.
That's not what I asked.
i will try to take screenshots 🙂
Another way to go about it is to visualize the agent path. Then you can step through the frames in the editor to see what's going with the remaining path frame by frame.
ok thanks, I will try few more things, and I will try to take screenshots, and then I might ask again 🙂
I have this scene. How exactly I can navmesh on this blue part of the area?
Create a separate mesh in the same shape. You can't bake a navmesh off of textures and definitely not procedural renders.
what a bummer basically level design in blender?
didnt much on youtube or other guide
for open world navmesh gen
Not necessararily. There are tools in unity, like probuilder.
You could also write some editor script for generating a simple mesh in a similar shape automatically.
Navmesh is mainly intended for fully 3d scenes, which is why there is not workflow for 2d.
If you're not limited to navmesh, maybe consider other navigation solutions, like the A* package.
i mean im not exactly sure how exactly to setup the scene even
atleast easily
like if i paint water like that then automatically detected as water or sort
keep in mind scene is isometric game
might even have to improvise
Well, then that sounds like a more general problem.
I'd recommend going over the beginner pathways on !learn
!learn
didnt got it. Some blender i have to put somewhere?? Wonder how exactly i can extract mesh out of rendered texture even or atleast other alternative....
basically it'll split meshes or sort?
Many different ways. You could read it pixel by pixel, and build a mesh out of it(or some other data structure). Or do the same in a Compute shader.
Not sure what you're asking here.
i mean make things in somewhere like probuilder or blender. Have separated mesh with tags then bake under a child hierarchy
could be an advanced topic mind telling what sort of algorithm I should do first then set up the point based on vert points then have triangulated mesh out of it? It'll be pre-made anyway
Not sure what tags have anything to do with it. But yes, you need a mesh to be able to bake a navmesh.
One common technique that could be used is marching squares(or cubes). This allows taking a collection of points representing the geometry and generating a mesh out of it.
You can of course implement your own, but that would be quite a bit more complicated.
hey i need some help, say i had an npc walking around a city on pathways using the unity navmesh system, how would i get it to be able to cross streets only at cross walks and not walk across the road instead of using the pathways? But then how would i make it possible for them to do that when there in panic mode for example.
The simple answer is do have pay ways. Or rather patrol routes that the npcs would normally follow.
And when there's a panic let them move freely on the navmesh. Or not. They could run away on the road. It's a design choice.
thanks
Is there a behavior graph node that lets you append an item to a blackboard List variable? Or do I have to make an action node for it myself?
Hey, My boss uses NavMesh2D, but only the pivot is checked for walkable area. How can I make sure the whole body stays inside?
Thanks!
Anyone here has used Behaviour graph in Unity ? It's GUI based. I have stuck in problem, where property is not visible, even though I have used [CreateProperty] attribute. Let me send the code here.
``public partial class SearchForThePlayerAction : Action
{
[SerializeReference] public BlackboardVariable<GameObject> Self;
[SerializeReference] public BlackboardVariable<GameObject> Player;
[SerializeReference] public BlackboardVariable<GameObject> Sensor;
[SerializeReference] public BlackboardVariable<float> WaitingTime;
[CreateProperty] public float underDistance = 2.0f;
private Ghost ghost;
private LineOfSightSensor sensor;
private float currentTime = 0.0f;
protected override Status OnStart()
{
ghost = Self.Value.GetComponent<Ghost>();
sensor = Sensor.Value.GetComponent<LineOfSightSensor>();
currentTime = 0.0f;
return Status.Success;
}
protected override Status OnUpdate()
{
if(currentTime < WaitingTime)
{
currentTime += Time.deltaTime;
return Status.Running;
}
return Status.Success;
}
protected override void OnEnd()
{
}
} ``
Kind of a weird issue i'm having, my navmesh agent cosntantly has a destination of 5.63, 0.08, 18.82 which are the co-ords of the navmesh agents location 😕
but when I debug.log(agent.haspath) it returns False
Hello everyone I’m making a third person shooter, so I have an enemyAI. By itself it works fine (basically perfect). But when I right click and duplicate it and move another one to another location. They both just break and almost sink into the ground. This is an annoying issue and some help would be useful
You can snap objects to a surface by holding ctrl+shift and dragging the appropriate gizmo.
can someone help? my floor isn't getting anything baked onto it but small parts of the wall are. can someone help please?
can you show a screenshot or vidoe how it looks now and maybe of the inspectorr too
https://www.youtube.com/watch?v=SMWxCpLvrcc here is a official yt video, you might be missing something
its oging specifically on walls and i only want it on the floor
It seems like it's rotated..? The green arrow is supposed to correspond to "up" direction.
In unity y axis it up/down.
Assuming the gizmos are in global mode.
this did not work
What did not work?
what you said
I didn't really tell to do anything. Just to check. Checking something can't work/not work.
can someone link me to a recommended solution for updating navmesh surface at runtime?
I instantiate new objects which I want to connect to my existing navmesh.
https://www.youtube.com/watch?v=UGh4VSeKPNA
Or check out LlamaAcademy videos , he covers lots of topics on navmesh including real-time bake
In this video we’ll look at spawning in layouts and dynamically creating NavMesh surfaces during runtime, how to check when an agent has reached its, setting area costs and adding AI randomness for multiple characters.
If you want to follow along with this video, make sure to download the AI Navigation Package 2.0 from the Package Manager tog...
I've seen it,
I ended up going with async update navmesh and keeping only the last 10 instantiated navmeshes, clearing the rest
Hey all, been playing around with the behavior graph system and I find it's really cool. Unfortunatley, I'm having a bit of a strange issue when trying to set the value of a vector3 blackboard variable from inside a custom node. No matter what I try, the value gets set to infinity.
using System;
using Unity.Behavior;
using UnityEngine;
using Action = Unity.Behavior.Action;
using Unity.Properties;
[Serializable, GeneratePropertyBag]
[NodeDescription(name: "Get Object Location", story: "Save [SceneObject] location to [Vector]", category: "Action/GameObject", id: "9345a4d36940e47ee4796f1bf3ef58ac")]
public partial class GetObjectLocationAction : Action
{
[SerializeReference] public BlackboardVariable<GameObject> SceneObject = new();
[SerializeReference] public BlackboardVariable<Vector3> Vector = new();
Vector3 m_lastPos;
protected override Status OnStart()
{
if (SceneObject is null || SceneObject.Value == null || SceneObject.Value.transform == null)
{
Vector.Value = m_lastPos;
return Status.Success;
}
m_lastPos = new Vector3(SceneObject.Value.transform.position.x, SceneObject.Value.transform.position.y, SceneObject.Value.transform.position.z);
Vector.Value = m_lastPos;
return Status.Success;
}
}
I've tried guarding against not having a value, I've tried saving the last know good value, I've tried most of what I can think of. The end goal was to save the last know good position of the player and to search withing a radius upon losing the player
Here is my behavior tree
Anyone have any idea what could be going wrong?
calculatepath is single thread and one-shot, super expensive
is it better to increase the tile size, then?
When i try to adjust my Agent Type radius and rebake the navmesh, my agent will slide around the map if i bump into it with my character, bouncing off the walls like an air hockey puck. When disabling the Navmesh agent, it fixes the issue. Also when setting the Agent Type radius to 0.11 or lower, it works but anything higher it begins to slide around.
currently radius is 0.11 and height is 0.24. i have the navmesh agent radius and height the same. I would like to increase it so the agent isint clipping into walls but any attempt breaks it… Anyone know a cause of why this happens?
so if i set the Nav Mesh Agent Radius to 0, it wont fly around with the Agent Type radius set to 2.0. im very confused.
I don't know if someone could help me with a behavior tree, I'm making a boss, the player has to place 4 fragments in their 4 corresponding altars and I want that when placing a fragment, 25% of the boss's life is removed. How could I make the behavior tree scheme?
OMFG peeps! you have to dump this POS unity navmesh and buy Aron's astar Pro!
250 wormies running after me and it runs on quest 2!
I mean, navmesh is pretty fast too, depending on the settings. I think Brackeys had a 8 year old video where they test 1000 agents navigating with different settings.
not insta path on large environment. brackeys always half assed his tests
hello,
🆘 NEED HELP 🆘
I am having problem with my nav mesh agents recognizing each other's collider boxes. Is there a way to make Navmesh agents work based on the colliders instead of the radius to avoid getting into each other?
I have few agents, each contining 10 cubes, and they have their box collider set to cover all those cubes. All agents (not individual cubes) have navmesh agent but they still get into each other when moving.
Now I know making radius bigger solves this but the radius works only in cylindrical shape and my formation is a rectangle.
Is there a way to solve this?
I need help with this
Each fragment will also be linked to an elemental power of the boss. If I place the fire fragment on its corresponding altar, I want the boss to not only lose 25% of his life but also not be able to use the fire ability. I don't know if it's too complex. Maybe I should make it simpler
the trick to super fast parting in unity navmesh is to lower mesh detail and have large tiles. carving is async anyway
what does the error of "Failed to create agent because it is not close enough to the NavMesh" ?
Exactly what it says. The navmesh agent needs to be places precisely on the navmesh for it to work.
hi i have an wierd problem pls healp 🙁
are there any known relatively performance-cheap methods of getting an agent to find it's way out of simple concavities?
Right now mine is using a steering vector looking for the shortest unblocked passage to its destination (directly behind the other units) but that only works on convex obstacle arrangements
trying to find some way to help it take a shorter path 
Attribute the distance a value and make it choose the lower value, IE if the distance between point A and B is 5 allocate it a value of 5, if the distance between A and C is 3 allocate it the value of 3 and tell it to chose the lower value etc
So i have shooter agent i want to spawn on my navmesh, but i keep getting errors when the simulation starts as the name keeps getting changed to "shooter(clone)". I want it to find the object "Shooter" I can dm ppl too as well if they want to see the script and such to discuss more in depth
Any time a prefab is instantiated it is automatically prefab name(clone) try to find a component that prefab would have attached, IE a script
so create a script and attach a prefab to it?
Other way, create your prefab (let's call it Enemy) and in enemy as a game component you may have a script called EnemyAI, you can tell your script to find the enemy based on the script called EnemyAI
wait i still don't get it
On the right, you can see a Manager script with enemy prefab. The script is attached to the Game Object, the enemy prefab also has a script attached which can run when it is spawned in
The script for Manager has a method that does a check for If(FindAnyObjectByType<EnemyAI>()){ Do Code }
can i dm you for more questions?
Yeah feel free
Can you not generate a NavMesh surface with a mesh collider when using Physics Colliders? If I bake a NavMesh with these settings on this object with just a mesh collider there are no visible navmesh surfaces at all and my agent can't navigate on it
You may want to play around with the settings of your navmesh, your terrain is very varied in heights and slopes, the navMesh would struggle
I'll give it a quick go but I'd expect even some polygons and flatter sections
Lemme alter the max slope even higher I guess
Honestly hard to judge sometimes I've had random triangle patches not be built on flat surfaces before
Oh yeah, its just a few small patches here
I'll edit some more parameters and check, atleast it's generating something
So that answers your original question of can you.. yes, but the terrains heights are what's maybe an issue
Some progress atleast, but there are still really flat areas like this where I can't get it to generate patches, odd
Read your yellow warnings on the bottom of the component
Oh whoops
Well it still didn't work beforehand so
But let me fix that anyways my bad lol
Still the same issue, and here's a better look at the terrain mesh
The material is front face only so it's not a normal issue
Try smoothing it out a little, low poly doesn't have to have low poly terrain too, some smoothness may help the navmesh
If I try artifically doing this by just scaling it on the Z axis, still no luck. Really odd, not sure if I'm missing an important setting to override?
I mean this is about as flat as possible which is why I was wondering iif it's a problem with mesh colliders
Mesh collider is required or you'll fall through the terrain, or at least physics objects would
Yeah I have one
The green outline is the shape of it so after scaling the bumpiness is definetly not an issue
I even tried setting the Z scale to 0 so it's just a plane but still nothing
Ohh wait I think I got it
I think the actual rotation of the object matters even if it's flat with respect to the world up vector, since if I make a box collider I get this as the baked mesh
So I just need to apply rotation in Blender and reexport, let me give it a shot
Okay yea, that worked
Should change my export settings next tiime
Thanks for the help 🙏
Hey no worries, was a difficult challenge
I kinda expected navmeshes to work with the world up so I'm surprised it works with the mesh-relativee up
i'm very new to this, i'm using aron granberg's a* project and the setup guide is telling me to add a component called "follower entity" which just isn't there when i search for it
can anyone help me with this?
Is it possible to directly replace Unity's navmesh with a Mesh object?
No.
oh yeah? then what's this?
private void Filter() {
NavMesh.RemoveAllNavMeshData();
List<int> newIndices = new();
foreach (int triIndex in island) {
for (int i = 0; i < 3; i++) { newIndices.Add(mesh.indices[triIndex * 3 + i]); }
}
Mesh m = new();
m.vertices = mesh.vertices;
m.SetTriangles(newIndices, 0);
m.RecalculateBounds();
NavMeshBuildSource source = new NavMeshBuildSource {
shape = NavMeshBuildSourceShape.Mesh,
sourceObject = m,
transform = Matrix4x4.identity,
area = 0
};
var sources = new List<NavMeshBuildSource> { source };
NavMeshBuilder.UpdateNavMeshData(GetComponent<NavMeshSurface>().navMeshData, NavMesh.GetSettingsByID(0), sources, m.bounds);
}
That's rebuilding the navmesh from a mesh data. Not "replace a navmesh with a mesh".
Yeah I know... It was the best workaround I could come up with
You don't specifically require a navmesh to do ai navigation... It just makes it much easier.. I'd just work with navmesh than have to do all the code to handle a non navmesh surface, IE the scoring system for how difficult terrain is etc
It's pretty awful too. The workflow becomes
- Bake nav mesh in navmeshsurface
- Fidget with
startrandomly until it lands on a triangle that's on the island you want. (this is the point of the system, to isolate one island of nav) - Click the first button
- Go back to the nav bake settings and change the agent radius to something ridiculously small like 0.05
- Apply
- Reset the agent radius for the next time you need it
This fucking sucks. All I want to do is to filter the navmesh to only keep the largest contiguous area
The result is also weird too. It's not what the mesh you passed in is. Minimizing the agent radius helps, but it's still a quantized version of the mesh
How? I'm not using NavMeshAgent, only the nav mesh itself to get pathing.
The other things that I use nav for are generating cover points, and generating dynamic patrol paths. I rely on the NavMesh API for stuff like find nearest point
Well navmesh is a 'modern' concept. The way ai used to be run was generally a point based system
Think of it like this you have 10 points. If there is a rock in your path that is 2 points but everywhere else is 1 point, your ai works out the path that gets to the spot using the 10 allocated points (or less)
don't worry anymore, i've decided i'm over complicating things
i'm just going to use a basic patrol system with set vantage points, it's all i need for what i want
Okay and how does it pathfind around the rock?
So let's say you have a grid. We will make this grid a 3x3
xxx
xxx if we put the rock in the centre
xxx
xxx
xrx
xxx
It calculates that the rock is 2 points the rest of the path is 1 per spot
Then it would go through some quick calculations to work out the maths and if the sum total is less it takes that route
So you would write something that checks if distance from character to destination is less than a certain distance and it has less points than required. Take that route.
In games with followers it can adjust based on your character also why followers tend to go around a rock or take a longer route down a cliff than jumping for example
Is there genuinely no way, in Unity, to modify the nav mesh
I don't really know but if it seems you cannot, you should look for alternatives. I bet you could use custom meshes on the A* Project for example (by quick look it looks you can at least use navmeshes from 3D files, I would be surprised if you couldn't do the same via code too)
So I'd have to drop 120 bucks to do anything serious with nav
free engine my ass
Okay. Thank you
Where did you get the 120 from? Is there something specific you need from the pro?
Does the navmesh rebuilding not satisfy your needs?
How should I go about making navmeshsurfaces for procedurally generated maps?
You can generate navmeshsurfaces at runtime. If the map is procedurally generated from prefabs, you can also bake navmeshsurfaces in prefabs and then connect them after map generation (I think you would have to use NavMeshLinks here)
Couldnt you also just use navmeshobstacle?
Is this related to ai-navigation?
The neighboring channel is the correct place
#1202574086115557446
I have an a* pathfinding implementation that I am having issues getting it to return optimal paths. Almost everywhere on my map it works as expected, except for right here.
The heuristic branches out and for some reason the right-most branch is overtaking the closer left-most branch, which ultimately reaches the goal. Then I do a funnel algorithm to get a shorter tunnel through those triangles
The issue is obvious, the funnel version has this huge gap around empty passable space that would produce a shorter path is being ignored.
How can I improve it's behaviour? I can share code snippets if it helps.
The green path is the shorter distance, but the hscore/gscore think the red path is shorter and I cannot figure out how to make it understand that its not
i used to have a project in 2019 (might be older... not sure (i dont have the project anymore 💔 )) which i do remember that i use the navmesh (baked scene) to create a vectoe3[] with the waypoints with the corners but i also remember that i didnt have agents on the scene.
does anyone know how to do that?
hi
i finded 😅
i was searching for a function with (out NavMeshPath)
it was dumb of my part
simple as that
I need to take the navmesh and separate out only the largest connected island. Having little inaccessible islands in the level would break several other systems I have
This requires actual modification of the mesh
What exactly is the issue with having these islands? Can't you adapt your systems to check for the possibility of making a path to/from these islands to points of interest?
Or exclude the objects that would create these isles from the navmesh in the first place.
https://github.com/h8man/NavMeshPlus All of the examples I see with this plugin use an Agent to move. I don't want that as it looks terrible. Is there a way to get the next point so I can hard code the movement myself? I'm pretty frustrated that Unity lacks a 1st party solution NGL.
Unity NavMesh 2D Pathfinding. Contribute to h8man/NavMeshPlus development by creating an account on GitHub.
How can I make an advanced chase AI where the AI bot has to see you to chase you?
- implement chase feature.
- implement sight feature.
- combine.
- profit..?
how do i optimize the navigation for hundreds of agents?
Look
The purple points are a grid aligned even sample of the nav mesh. The green points are the patrol points dynamically generated using those points
Now, imagine the insides of walls, every roof, every little crevice that Unity thinks is navigable also having such a purple point
It completely breaks patrols
My little hack to make this work is atrocious. I've already detailed about it here. It works, but I feel like it constantly gets deserialized for some reason or another, and I have to restart the whole bake process again
That's just one system
My dynamic cover also utilizes the nav mesh to generate spots where the AI could go to protect itself from gunfire. It would break completely if there are hundreds of patches of unreachable nav
Now, could I spend several hours manually filtering out every little crevice that Unity thinks can be navved to with modifiers? Sure. I am not going to do that. This is insane, and a complete failure of Unity's navmesh system.
Do you know about A*? Can you tell me if it would fix my problems?
Ultimately, the issue is that you don't have a way to tell the algorithm what you want to be walkable and what not. So you'll have the same issue with A*. At least if you're gonna bake based on meshes or colliders.
Now, a simple solution that you'd use in such scenario is generate a temporary mesh of the floor only(or whatever walkable area you want) and bake the navmesh based on that. Then delete or disable it. You can have a small editor script set up that would do that and bake the mesh whenever you want.
Alternatively, you mentioned a grid. If it represents only the walkable areas, then you could probably use it in A* and not worry about anything else, though I haven't used the A* package, so take it with a grain of salt.
and bake the navmesh based on that.
This is the hack. And it blows, because it modifies the mesh. Certain thin walkways will just no longer exist. The mesh is rebaked in weird ways
I cannot just replace the navmesh with the mesh I want
Well, you need to adjust the navmesh settings or the generated mesh to avoid these issues. Think walkways non existing are often due to agent settings, like agent radius. If unity think a walkway is too thin for an agent to fit, it would not generate it. This is expected behavior.
Okay? It's generating the path based off of the generated path
think of a thin walkway. It generates a thin nav. To filter so the nav is only that, I do some AI-generated black magic and bake again using only that surface, and now it disappears
You end up baking twice and the result is not great
I've no clue what you're doing and what exact issue you're facing. You'll need to share more details(screenshots or a video demonstrating the issue, code, scene setup, etc...), if you need more help on this.
What I suggested is just this:
Generate mesh of the surface via a simple script -> bake navmesh based on that mesh only.
Before that configure relevant settings correctly(like reducing the agent radius to avoid skipping of thin/small areas).
in theory if the second bake is using extremely lenient settings it should cover the entirety of your generated cherry picked mesh
Yes, in an absolute best case scenario where I spend another 30 seconds fiddling with agent settings to minimize radius and voxel size, and then reverting them, I would get a less degraded result. Wonderful
I bought A*. It lets me do what I actually want to do and is lightyears ahead of Unity's trash.
(the suggestion here would have been to do this via code, not by hand)
Why would you need to revert them?? 
These settings are meant to represent the actual properties of the agent.
If your character is 1 meter wide, it wouldn't be able to fit in a 0.9 m wide walkway. The navmesh padding the edges and cutting out thin walkways is meant to represent that phenomenon. If you understand this, it makes total sense and is easily fixable by adjusting the settings.
Overall just anecdotally I’ve had a pretty positive experience with the navmesh package. My two biggest wishes are
-
It would be nice if it had the mesh detail available in a way where I could retrieve the mesh as submeshes based on “islands”/areas with full separation from eachother
-
It would be really nice if we had a way to set the navmesh directly by supplying the mesh data
Oh actually the amount of areas allowed being a global project wise bitmask is unideal in some situations too, would prefer if it was a ScriptableObject you would plug into the surface and agents
hey guys, don't know if this is the right channel but i wanted to ask if someone is familiar with unity ml agents. im trying to implement a funtionality for my thesis
- Bake the navmesh normally
- Click a button on my editor script to select the island that I want
- Go into agent radius change to 0.00001 or some shit like that
- Click the button on my editor script to do the black magic on the navmesh surface, rebaking now with only the island and new character radius
- Go back into agent radius and revert the change to the normal character radius
- Reload the scene because I have to now
- Write a script that:
- Generates the floor mesh.
- Runs a Navmesh bake(with any param modifications if needed).
- Run the script.
- Done.
You don't need to modify the agent radius constantly. You need to set it up to a reasonable value(if you want it to walk on walkways with a radius of 0.2, the agent radius needs to be <0.2). No need to change it just for the bake. Keep it the same value all the way.
(and if you did need to adjust the agent radius, that can be done in code too)
Hi Guys I'm trying to get the nav mesh bounds inside a behaviour agent I already have the blackboard variable but for some reason I can get the values of the navmesh inside my action script
You can get the NavMeshSettings easily via NavMesh.GetSettingsByID(), but how do you re-apply those changes? I want to lower the minArea in my project, but have not found a way to do so.
Hey, does anyone know why unity bakes two separate navmeshes? these two navmesh surface components (with volume) have the same settings, but still it wont bake into one navmesh, so agents can move across these platforms. Any ideas for a solution? A script would be nice, because I wanna bake them in runtime
hey, guys! For one reason, nav mesh surface isnt connected. Why it's happening?
Hey guys, uhm, can anyone help me with runtime dynamic areas? I'm trying to get a object the player can build to work with having an area so that enemies avoid it if possible, baking works, but on runtime it will just not work
Like I doubt that I have to re bake the whole mesh always after placing the avoid area, thought it would work dynamically like carving from obstacle
But I can't figure out how
is this normal behavior for agents?
im trying to keep my agent within the 4 walls, but with a distance from the target
im brand new to this AI stuff and didnt run the training for long
but i dont think it should behave in this way
my observation and movement code is as follows
public override void CollectObservations(VectorSensor sensor)
{
sensor.AddObservation(transform.position);
sensor.AddObservation(target.position);
for (int i = 0; i < walls.Count; i++) {
sensor.AddObservation(walls[i].position);
}
//base.CollectObservations(sensor);
}
public override void OnActionReceived(ActionBuffers actions)
{
//Debug.Log(actions.DiscreteActions[0]);
float first = actions.ContinuousActions[0];
float second = actions.ContinuousActions[1];
//controller.Move(new Vector3(first, 0, second) * Time.deltaTime * walkSpeed);
//GetComponent<Rigidbody>().linearVelocity =
GetComponent<Rigidbody>().MovePosition(transform.position + new Vector3(first, 0, second) * Time.deltaTime * walkSpeed);
//transform.position += new Vector3(first, 0, second) * Time.deltaTime * walkSpeed;
}
public override void Heuristic(in ActionBuffers actionsOut)
{
ActionSegment<float> actions = actionsOut.ContinuousActions;
actions[0] = Input.GetAxisRaw("Horizontal");
actions[1] = Input.GetAxisRaw("Vertical");
//base.Heuristic(actionsOut);
}
Afaik that's intended behavior, What problem are you trying to solve here?
I forget the name but looks like its the setting that determines the distance between walls/obstacles
there might not be enough width in that doorway given those settings
(see how theres a gap between the nav and the walls next to the door)
the agents can't move from one mesh to another mesh because they're separate islands. i know navmesh links would be a solution, but it would be better imo if there's a way to bake them into 1 single mesh
there might be a misunderstanding on mine or your behalf
a single navmesh surface can create a navmeshbake that affects multiple meshes
in most cases you only want 1 navmesh surface period
i have multiple room prefabs that will be used for procedural map generation. each room has its own volume of navmesh surface. the thing is when i bake them all each room as own separated navmesh baked so the agents cannot move between/across rooms. the navmeshes are overlapping at doorframes just like in the picture above (where the darker blue color is the part where its overlapping)
as far as i am aware, multiple nav mesh surfaces will never bake in a way that connects them, in your initial question you asked why that isn't happening, which is because its not something that does happen
I believe fairly common practice is to instantiate your rooms then use 1 navmeshsurface to bake them, either via volume area or by parenting the room instances under the navmeshsurface and either collecting them as children or colliders (based on the surface settings)
hmmm i understand :/ that sucks...
i am thinking of buyin a* project pro but damn 130€ is a lot
What is your problem with that method?
if i bake globally it will bake like everything, not just the areas i want yk?
ik a solution would be creating a separate layer for exactly these areas i wanna bake, but meh... not what i want
You might want to look at the NavMeshModifier and NavMeshModifierVolume components
😅
You can write your own.. it's much easier than you think
hi... can someone help me out w how to use ML agents in Unity, or suggest me some good tutorials
Are there any obvious gotcha reasons why a baked navmesh would work differently in build than versus the editor?
Could this be a loading thing? Where maybe in editor the nav mesh loads first, but in the standalone build the agents are faster?
I'm getting Nav Mesh Agent can't find a nav mesh errors but only in standalone builds, and what DOES work is in the wrong spot
I'm not building a nav mesh at runtime either, this is baked in stuff
it looks like this might be a long standing issue?
https://discussions.unity.com/t/solved-navmesh-not-included-in-build-android/546542
https://discussions.unity.com/t/navmeshagent-surface-component-not-loading-in-build/756257
https://discussions.unity.com/t/failed-to-create-agent-because-there-is-no-valid-navmesh-only-on-mobile-device/747793
https://discussions.unity.com/t/no-valid-navmesh-in-executable/811160/2
Could be a floating point error.
You should snap the agent to the closest point on navmesh before using it.
I actually tried deleting and replacing it and the error persisted - but that's a good idea
thank you fellow lich!
ok thanks
@glacial wagon I actually had that issue in a horror game I was making. The problem was exactly what dlich said, the agent was slightly off the navmesh and snapping it to the closest point at start fixed it.
Of course I sat there debugging for like ~2 hours and ended up figuring that out myself. Probably wouldn't have almost ripped my hair out if I had of asked in here first haha
I got it to work!!!
You're the best 😁😁😁
NavMeshAgent Issue: Multiple Agents Following the Exact Same Path Despite Different Start Points
Hey everyone,
I'm developing a city defense game and running into a confusing issue with enemy AI pathfinding.
The Goal:
Enemies need to spawn randomly around the perimeter of the city and move toward a single, central target point (the city core). I'm using Unity's NavMeshAgent component for movement.
The Problem: Although each enemy agent is spawned at a unique, random position on the NavMesh and is assigned the same destination, they are all moving along the exact same path. They essentially form a single-file line as if they are all starting from the same position.
What I've Checked:
I verify that each agent's start position (where they spawn) is indeed unique and different.
I ensure that I am calling agent.destination = _center individually for each enemy's NavMeshAgent
The target position is a single, static Vector3 at the center of the map.
My Question:
Why would multiple NavMeshAgent components, starting from different points, calculate and follow an identical path to a single destination? Is there a scenario where agents might be accidentally sharing a path object or where the NavMesh is treating widely separated start points as the same?
Any suggestions on what to look for—especially in relation to the NavMeshAgent setup or scene hierarchy—would be greatly appreciated!
Solved thanks to a reddit user.
Because they can't reach the center. When the point is out of range - each NavMesh agent will search for the closest point to the destination, not the shortest path.
And for some reason the closest point to the center is there, near the left wall. So all agent go to the closest to the center point they can find.
Hello there, i'm having a trouble using navmeshes.
[Context]
I'm making a block game that would have a bunch of entities, and the terrain is regrouped and generated by chunks.
Some chunks are updated quite often (a couple of times per seconds)
At first i was creating a navmesh for the whole world and re-baking it each time a chunk is updated. However it was >150ms for each baking.
Another idea I thought was to have for each chunk its own navMeshArea. However their is a small space without a navMesh area at the junction of two chunks.
[Question]
- Is their a way to refresh only a certain part of a navMeshArea ? (in case I only have one NavMeshArea)
- Is it possible to have something that could merge multiple NavMeshArea while limiting the computation time ?
When I try to bake this map, it makes a large white box around it, why is it? I know its a building but it should create a path on the grounds no? It only makes this large box around the building and no blue navmesh (script also throws me errors about invalid navmeshes)
Anybody can help me please? Might be the scaling? Also these are static.
You found how fix it?
No, you having the same problem?
Just let me know if anybody can help me with it
Okay so here's my obstacle
Issue I have is with this
The NPC which is the purple looking alien is not moving within the nav mesh surface
I tried a lot like baking it, using static, and almost everything I can do get it to move around the surface but it doesn't
If anyone can help me, that would be great!
what is "obstacle 2 pc and camera"?
That's the player character with the camera implemented
He told us specifically to make sure to use that parent
I thought that might've been a problem as well, but I don't know completely
when you start the game and move around, you notice that the npc doesnt move at all, right? do you get any errors in your console? make sure errors are visible
I do get an error about something else but it works fine. Regarding the NPC, this is what happens
preferably convert that to an mp4
video's not loading for some reason
nvm it's working now
Oh okay great
expand your console and look for other errors. there may be more than 1
hide everything other than errors and press collapse. then send another screenshot
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Which code do I send?
the npc movment code
your current state is set to patrol and you have no waypoints set in the inspector, so there is nothing for it to do.
Change your state to "pursuing" for it to follow the player
also did your teacher write this code?
Yes
it's dogshit
I don't know how to write code
you'd honestly be better off with something ai generated (not saying you should do that but it would genuinely be better than whatever the hell this is)
I've used AI like chatgpt and gemini to help me with this but even they couldn't
But let me see if that works regarding patrol to pursuing
what did you ask it? this is a super simple problem and ai should be able to easily fix this
I asked how to fix this and it just told me to bake it which I've already done many times
did you give it your code?
No
then obviously it's not gonna know that there is something wrong with the code
I didn't event know there was something in the code that was messing up the project
Like I said, he didn't teach us coding or scripting or anything like that
you should really file a complaint against him or speak to whoever is in charge after him. this is unacceptable behavior for a teacher
btw, you can learn coding on your own
there are tons of great tutorials out there
I gotta look into those
Unfortunately, I think he's the only person who knows Unity, so they keep him
even if that was the case, he's not teaching you anything, so what's the point
TBF I've watched a lot of youtube videos and tutorials on Unity to figure this out
And the cc does have a game design degree that I want so I just take it in
Thankfully his class ends in like 3 weeks
did my suggestion fix your problem btw?
I'm trying to open visual studios with this but I don't know how to get the code to appear
double click your script in your project
Okay I think I needed to download something for unity to open with visual studios
My bad
Also thank you so much for helping!
You've done a lot for me
you shouldnt need anything, but you may need to configure your IDE
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
also in unity, go to edit > preferences > external tools and see what is set for External Script Editor
It's visual studios
yeah then you may just need to configure your ide
Alright after downloading that installer I see the code now
So I just save it, correct?
yeah after changing the state, you can press ctrl + s to save
Still doesn't work
what did you change
Patrol to pursuing
send a screenshot of what your code looks like now. capitalization matters
oh, also, you need to set a waypoint for it to work
Waypoint?
where it says Waypoints, expand that, press the plus sign, and add a waypoint. you should just be able to add the player's transform in there
yeah that should work
That didn't work as well
wait is that the prefab?
holy hell, your teacher's code is so bad it made me think that you did something wrong
nevermind my last comment, you did it correctly
sorry, i read the code wrong when i suggested that you needed to add a waypoint. you actually dont need it and can remove it
Okay I've removed it
you are missing a reference, but im not sure what it's supposed to be
Like for the player character?
something needs to be put here for "head"
the code is trying to access something on the head but cant
Should I put the player character again on the head?
You need to configure your IDE first.
actually, nevermind, it is being initialized in start
this code is so dogshit and this is a nightmare to look through
How do I do this?
You've been linked it already #🤖┃ai-navigation message
i suspect that the logic for angle isn't working properly, but im not sure how it's supposed to work because of the lack of detail
if you can get away with it, follow a tutorial and use the code from that instead of this trash
Okay so I am updating visual studios on both unity and visual studios
Hopefully that works but if it doesn't, I'll try to get the code from somewhere else
Even my teacher told me to just ask ChatGPT if there were questions
configuring your ide has nothing to do with the code itself
definitely report this guy. what a garbage teacher
It's strange since in his scene the NPC does actually work
in a lot of places nowadays that is standard behaviour and not a reportable offense :/
So I figured it has to be something with mines
wow this actually digusts me
I tried everything I can but it doesn't work for my scene
I'll try to see if I can just create or use code from somewhere else
Thanks for everyone trying to help!
I am having some issue with NavMesh agent always hugging the edge of the NavMesh Surface and they end up getting stuck or slowed because they keep trying to walk directly on the edge. Anyone know if there's a solution so they stay away from the edge and stay more close to the middle?
Use a if statement? Or have path nodes to have that be automated and if it's close enough to a target it would ignore that but else it won't and follow the middle of the node
This is to clean up what already exist but you just need to verify if the infrastructure works for it
Actually you can probably remove that edge from the pathing area and maybe only have it for vaulting or jumping off and only do it if you can get to the target faster... Minecraft does this... Also 7 days to die
If you put valuation pathing instead
Depends on the base infrastructure and what you want when you implement the fix
In theory you could bake with a much smaller minimum region area, sample the results and create a mesh out of it, add a navmeshmodifier to that mesh collider and then bake a second time setup so the mesh area has a lower area cost so it's preferable for agents to be more in the middle
Hello guys, I'm releasing City Of Light today,
This is a 3D replica of my city (Paris) for data collection and model training with embodied agent and multiple sensors,
There is a video showcacing its features available here : https://www.youtube.com/watch?v=KhIO3J9oGr8
COL leverages a new library based on shared memory segment allowing data transfer way faster than ML-Agents. I provide a bit more details in a post I created in the ressources channel !
Come there to discuss it if you are interested,
Respectfully,
Ilias
City of Light (COL) is a Unity-based, city-scale simulator of Paris built for high-throughput embodied and sim-to-real research. It fuses public geospatial data into geo-anchored 3D tiles and streams synchronized multi-sensor observations (RGB, depth, normals, semantics) to Python.
If you use COL in your research, please star the repo and cite ...
The primary reason is that NavMeshes usually pathfinds on edges and vertices instead of the center of each triangle. This makes the character walk alongside the wall, as thats the path it calculated. Ya can improve this slightly by increasing the agent radius to avoid fine-grain details. You can also combine the agent with obstacle avoidance. Either by having the character separately from it's agent, and doing the movement yourself, which allows you to apply a wide range of techniques. Or you could create your own simplified agent, where your only constraints is Unity and It's Navigation library.
I recommend having a look at steering behaviors as a good starting point 🙂 https://www.red3d.com/cwr/steer/gdc99/
This paper presents solutions for one requirement of autonomous
characters in animation and games: the ability to navigate around
their world in a life-like and improvisational manner.
im making a top down simulation game and at the start the terrain has a single road going through the town and then some grass. the grass is walkable with a weight of 1 and im using a series of navmesh modifier volumes to mark the road area as road which is a value of 0.5 so the npcs favor it.
when the player starts placing their own roads down and expanding out into the grass area what's the best way for that new area to be marked as road so they prefer to use it when walking to a newly built building? my understanding is if i had a gameobject with more modifier volumes i would need to rebake each time, but that causes a noticeable hitch, so what's the best way to achieve what im looking to do? thanks
how would one check if a nav agents path Is Intersected by player line of sight
Good evening you all! I am not familiar with AI pathfinding, I was wondering where i should start with it. Any great resources youve found useful by any chance?
Usually you use perception for npc while the player is actual human who can see the scene. So my question will be why you need that? I might be able to help. 😊
im trying to make an ai that hides from the player and before i make him move i need to check if his path is gonna intersect the players view
I think you build a perception for the AI and let it keep checking while moving. If it sees the player, they should change the path to hide or go in the other direction. That makes more sense as the NPC should not be able to anticipate / know the player location without seeing them. 😊.. my thoughts at least.
i want it to be kind of like the bracken from lethal company so that wouldnt really work for that, i think its fine if the ai always knows where the player is, cuz its only that one enemy
espiecally cuz the player can fight back
Sure! You can do that. Check CalculatePath function then. Would this help?
https://docs.unity3d.com/ScriptReference/AI.NavMesh.CalculatePath.html
i think this would work but the part im stuck on is letting it know if the path to the node is in view
You can check if a point is in the player camera frustum. I don't remember the exact api, so start from looking at the camera api docs.
wouldnt it count as visible if i "saw" it through a wall?
You could make raycast/spherecast checks against every point that IS in the frustum to see if it's behind a wall or some other object.
I have an idea but not 100% how it should work out! Attach a isTrigger sphere collider to the player. Attach a script to the NPC the get the calculated path points, then itirate thru the points and check if it intersect with the player collider. You can use, Physics.SphereCast for that.
oh yeah ur right
ill try this one too actually maybe this could work
Hii I have an issue that I’ve been trying to resolve but I can’t figure it out. I completed the roll a ball tutorial and now im adding another plane and a ramp leading up to it. My ball goes up the plane fine but when my ai chases me it stops at the very top of the ramp and doesn’t come into the plane (I baked everything too) pls help
I am doing this tutorial rn. I duplicated the plane and pressed Bake in the surface component and AI is following me when I am running on the new plane. maybe you forgot to save?
Ahhh I figured it out thank u tho!!
Now I have another issue regarding the countdown timer tho 😭
I am trying to train Arc Raiders flying enemy like AIs
I would like to discuss approaches on training this kinds of AI
has anyone attempted this kind of training?
You made initial post in the correct channel. This is Navmesh and AI coding channel as descriptions says.
No need to cross-post.
is it possible to change a navmesh area at runtime without rebuilding the entire navmesh ?
i cant see a way to do it from the components, other than using obstacle but i just want to restrict an area to a specific agent
I am trying to make flying AI that navigates through places and search for "score point". I am struggling as to how to design its sensors and storing what it detects, has anyone tried this kind of AI?
You'll probably need to implement 3d A*. As for the sensors, I don't see how they should be different compared to non flying AI.
Have you checked the hummingbird tutorial? This is an great and detailed example for a flying AI agent.
Hey I'm checking the AI package, and honestly it seems a bit basic when compared to stuff like A* Project, which receives more updates and has way more features, is that like, kinda the point? I'm thinking of basic seek and destroy AI, but unity's package lacks, for example, node graphs, which I think are the simpler form of navigation and excellent for aerial / flying agents and A* Project does have it.
Also A* Project has burst and other features that makes it do what Unity does but better either way
I think that what I want to ask is whenever would anybody truly recommend purchasing the A* Project or not.
Given my case where I can probably reimplement node graphs myself, but not as good.
Unity navmesh implementation is not exposed, so you can't possibly see all of it. They're using A* (the algorithm, not the package) under the hood, so it's pretty similar. They have node graph as well(you can't do A* without a node graph), though it's based on the baked navmesh, not the whole 3d space, which is supposed to make it faster.
Needless to say, engine internal code is likely burst compiled, and uses multitgreading.
When you compare unity navmesh with the A* in terms of performance you're probably comparing apples to apples(for example unity adds a lot of extra, like dynamic obstacle avoidance, that adds a lot of overhead).
Yes, the built-in navigation solution has limitations(not suitable for 3d space/flying navigation, like any other engine feature and you can't customize it much, since most of it is close sourced. Which is exactly why third party solutions appeared. However for many use cases it's still pretty good.
They're not updating it because, there's not much room for improvement within the package design philosophy. If there's gonna be a new solution, it's probably gonna be a separate package.
If it suits your needs, while the default solution doesn't, sure.
This is entirely up to you. If you can afford to spend some money, it might be way more productive to use an existing solution, rather than reimplementing it yourself.
I'd disregard performance for now, unless it's a core requirement of your project( basically if every microsecond is important and you have many agents that need to navigate at the same time).
The gist of my thoughts are "I have the money and might as well just buy it instead of reinventing the wheel" to put it down. About Burst, I really don't know since from what I recall I didn't see anything regarding that on the changelog.
There wouldn't be anything on the changelog, since the pathfinding part is engine internal implementation. Besides, burst is just a C# -> SIMD compatible C++ source generator. There's no point in it for the C++ side code. It's very much possible that the pathfinding implementation was using simd instructions from the very start.
So at one frame I call agent.set destination on a target at unavailable area, I am seeing that NavMeshAgent.pathStatus is PathComplete (which is what I expect because an agent is already on closes navmesh edge)
Yet agent.pathPending returns true
Does that mean that path is still calculated? And PathComplete is about an old path?
The overall situation is that an agent goes to the corner/edge of navmesh, and waits till player move away from navmesh further
And then at the moment player go too far I want to differentiate at that frame if it's possible (yeah no much practical need but I am curious if it can be done) if agent need to move, or still at a closest spot
I assume if best case scenario set destination may generate path instantly, right? if no and it will always have one frame delay tell me
Yes. It's likely that you don't even have the new path yet, since it's async.
You could call navmesh calculate path to get it to generate the path immediately.
oh wow, thanks for telling me about this API
I am thinking of using it instead of usual set destination at times right after NPC finishes thier stun/attack/whatever animations if a player is close to make them a bit more responsive in close quarters combat, does that make sense?
Generally, I don't think there's gonna be much difference in terms of player experience. 1 frame difference is very hard to notice.
It makes sense to use when you need to do something with the path and not necessarily move along it.
For example, in my game I have an action queue system, where the character can execute a sequence of actions, like interacting with a prop. If the prop is out of reach, I calculate the path and check if it's reachable and whether there are doors along the path. If there are and the character can't open them, the whole action sequence is canceled.
@tardy junco what about regular use? Otherwise NPCs would essentially alaways go into idle state for one frame or a bit more after getting need to chase the player condition
or I ll have to incorporate idling piece into such states
if there is a cheap way to avoid that delay why not
By the way is there an API or something to see how ugh.... loaded is that agent pathfinding queue thingie.... I want to see when it starting to get too many requests and halting too bad
Yeah I already found out in settings I can increase it's efficiency by paying the price of performance, and I found out that I can setup cooldown timers according to checks of squared distance to target to optimize it
Hm... Wasn't the agent following the old path until a new path is ready?
If not, then I guess it would make sense to use it in such scenario as well.
I don't think there's any tool like that, but you can probably see the worker threads in the profiler.
I reset it the moment agent goes into a state where it meant to stay on one spot, oh yeah I forgot to mention into original message that I did reset path beforehand
I think... it would make more sense to call Stop instead, right?
I think not, not much difference at usual FPS setting
I feel like I am trying too hard but really want to do the most robust and reasonable mob AI script I can make
anyone have any idea how you'd handle a situation where you have an obstacle that carves the navmesh but also has a link to jump over it, yet it can also be a destination for an agent? I want it to handle both of these cases, but with my current setup, when the obstacle is the destination, it first triggers the link, jumps over, then goes back towards the obstacle.
im starting to realize that pathfinding, both 3d and 2d, is the main thing that causes me to get burnt out on my projects. I should really look into a easier method of implementing pathfinding
Is this a known bug?
I had stack overflow exception thrown in some logic that was using navmesh, and this caused navmesh to allocate 67 bytes (no im not joking) which was navmesh's build output path for some reason
and unity kept complaining about it unti i restarted
i think i can recreate that in a fresh project
it happened on 6.3f0 for me
67 bytes is not a lot, so it wouldn't be surprising if it allocates it in some scenarios.
Other than that, you should probably share the editor/player log after the crash. If you can reproduce it.
Is there a way to force a new velocity onto NavMeshAgent in a way so that its movement is not constrained? I use the NavMeshAgent for my player character and it is detecting jump points in real time, and i don't really know how to implement the jump itself because changing agent's velocity.y still constrains its movement to the navmesh. Is it a good idea to just switch to character controller for the jump and then switch right back to navmeshagent as player makes the jump? Won't there be any jitter because of component changes?
its not a crash, issue being, every time exception happens, it allocates even more on top of the previous allocations, and they dont go away until you restart the editor, meaning, it may go to 2000, and if exception happens for example on every frame, goodbye ram
OK, but you still need to share the logs.
Yes, you need to switch between the two. And, yes there might be weird behavior depending on how you do it.
Another option is to not use the agent at all. Calculate the path via the navmesh api and move your character along it manually.
Well, I kind of have to use navmeshagent because of the behavior I want to achieve. I want to constraint player’s movement to the surface, so that they can’t fall of the edge (similar to Assassin’s Creed). I tried to use a character controller and navmesh checks, but I couldn’t get it to work. Navmeshagent works perfectly for that (I set its velocity manually)
You can totally achieve that with the setup I suggested.
Alright, thanks for help
Just to make it clear, not navmesh "checks", but calculate the path and follow along it.
I had no isses with agents chasing the player since player is not an agent, however, now I see that when I made agents to treat each other as targets to chase, they are slowing down while enclosing
this is like, bad, is there a way to fix that without making my own "agent" component from almost scratch?
and without setting avoidance to none
Im having issues with Behavior where if I connect some nodes wrong it floods the console with error and capsizes my performance for the rest of the session
is there a way to refresh this easily without restarting the editor
Cause I removed the branching connection but its generally still being a problem when I move the node
Like im trying to connect the run in parralel to the attack node but its telling me that attack already has a connection somehow
This is the full tree btw
Hey guys, is there any way to make NavMeshAgent ignore obstacles at runtime?
you can simply not account the obstacle during the initial bake process. if you want the agent to avoid this obstacle later, the obstacle will need a NavMeshObstacle with Carve turned on.
heya all, was wondering if unity's navmesh would be more or less optomized than an A* pathfinder for a game where every enemy will be following one path(i will be running the pathfinding once and then creating a spline for the enemies to follow via setting location). the pathfinding will need to be ran only when the player is attempting to place a building ensuring that they never completely block all pathways to the enemy target
ah sorry, just realised i didnt mention, but probably should in case it affects the answer, the game will be grid based and all terrain will be flat, though certain enemies will be able to "fly" above towers(they will have their paths calculated ignoring towers but otherwise path along the ground as normal, thier meshes will just be in the air to give the impression of flight)
If it's just calculating a path once in a while, I don't think performance should even be among the considerations.
my issue is even though its only once in a while, its needed every time a player moves where they want to place their tower which can ofc change a lot if theyre dragging across the screen
cause i need to test the pathing every time to make sure the end point isnt blocked
This doesn't really tell me anything. How many times per frame do you expect the path to be calculated? Did you test it?
in my unreal engine prototype i used navmesh but unreal isnt exactly mobile optomised so i gotta leave my comfort zone again 😅
it will be calculated after the player moves their cursor to a new "tile" lets say for sake of convo after they move beyond a meter cubed, it will then recalculate as they would then be in a new "grid space"
That doesn't answer my question. How many times per frame?
Anyways, I recommend trying the simplest solution and stress testing with profiling.
Then deciding if the processing time is satisfactory for you or not.
i would imagine max once per frame, with double happening when the player attempts to place their tower
Then performance shouldn't be an issue IMHO, but again, test and profile.
my issue with that is that this is the core mechanic of my game, so if i do get my game to a playable state and then decide i need the other pathing method, it may cause me to need to completely rewrite everything
For me 1ms per frame might be fine, but for you unacceptable, so it's kinda hard to give any advices here.
Well, don't implement it in such a way that you would need to rewrite everything. Make it swappable.
so long as im able to tell when the pathing is rebuilt in code i should be able to work around it
is either better for that?
in unreal i had trouble for months which was fixed with a 0.05 second delay because the pathing updating was taking longer than a frame and i didnt catch on
That's extremely hard to answer. You'll need to test and compare. My estimations is that they're roughly the same, though navmesh could be slightly better on longer paths, as it operates on polygons rather than a constant size grid.
so neither would have a "finished rebuilding pathing" event or function that could be added easily?
If you use navmesh agents, the pathfinding is async, so you might need to wait a frame as well. If you use the navmesh api I think it's sync, so you should get the path immediately.
I don't see how that's related. This can definitely be implemented on your side.
including via navmesh? i have looked at my available settings in visual studio and was struggling to see an option to help me
Can you rephrase your question? What exactly are you trying to achieve? How are visual studio settings related to the topic?
ill admit im defintely more used to things like shooting and player controls in unity than AI, think last AI i made was in uni which was just simply move towards player at all times using navmesh
i would like to make a tower defense game where placing towers modifies the route the enemies take
this means that i need to modify the nav mesh every time the player updates a possible tower placement(which i call a hologram)
whenever the hologram moves, i need to recalculate the pathing in order to show a spline to the player which is where the enemies would move if the tower was placed in the location they choose
OK, so we're talking about modifying the navmesh rather than finding a path?
either or, i used navmesh for this example as thats what i used for my unreal demo
i need whatevers gonna be best for mobile
or preferably for a potato
my entire reason for this project is to be better at optomizing
In unity navmesh you'd achieve this by placing an obstacle with carving enabled and then recalculating the path
and that would be the best in the case of performance?
This is impossible to answer without testing.
In either case, the difference is probably not very big.
I don't think this is gonna be a performance bottleneck unless you do it hundreds of times per frame.
ok, lets simplify it to somthing you mentioned earlier, being able to switch it if its too bad
can both of these techniques be converted to splines?
so long as i have a spline i can implement the rest of my code i believe
If you have a path, sure. Though, I don't really see any reason to make it a spline anyway. You'd have a list of points usually.
hoping so too, which is why i was annoyed when people told me to do pathing per enemy when i made the unreal demo 😅
TRUE, you can just lerp between the points directly rather than using % progress along a spline
cant belive i never thought of that in the UE prototype 😅
then again i would still need a spline to visually show the player the path would i not?
Not really. You'd use a line renderer in unity. Not sure about unreal, but it probably has something similar.
A spline is something you'd use for curves and stuff.
closest i found was spline meshes which needed a bit of code to make cover a full spline but worked quite nice
this is an image from the old ipod touch game im loosely baing off of
yeah, main reason i used it was ease of use in getting the chevrons to show up like above, couldnt really find a way otherwise
If it's grid based, A* might make more sense logically. But it's not like you can't implement it with navmesh. Though you might struggle with it generating a path going through the center of the cells/tiles. Navmesh would prioritize the closest path in the mesh, that means it would go very close to corners and stuff.
And by the way, you don't have to use the A* package. You could implement your own. It's not that complicated. Unless you need all the extra features Tha package provides.
i didnt even know there was a package XD, my plan was if A* was best to just make it from scratch XD
Hello guys, I'm new to Unity and I'm currently working on a 2d boss rush project game and I wanted to know if yall have some advice to use well ai for boss ?
i dont mind the aliens doing either though, cause it would somewhat make sense since theyre still aliens in my game for them to take the shortest path, im not against them taking some diagonals if thats the shortest path
If you intend to develop it from scratch then the answer can vary from not "even close" to "a lot better", because it's entirely up to your implementation. Just to make it clear navmesh pathfinding is usually using A* under the hood as well.
ofc if i was using A* id code it so that if they were doing a diagonal with the gridbased and nothing was stopping them they could cut across diagonally anyways
Is this navigation related? If not, wrong channel.
I dont know honestly, what channel it should be
Maybe start in #💻┃unity-talk as it feels like you don't entirely understand what you want to ask.
Ye i think
so just before i leave you alone and let you finally get back to your life XD, id like to just ask one last question: how can i get a line of code to stop and wait for the navmesh to be fully built, as in my unreal prototype it would say that the path was valid, despite the tower blocking the path as the pathing had not rebuilt itself by the time the build check was being ran?
If you're using the navmesh api to calculate path, then it would stop and wait as it is, since it's a sync operation.
This function is synchronous. It performs path finding immediately which can adversely affect the frame rate when processing very long paths. It is recommended to only perform a few path finds per frame when, for example, evaluating distances to cover points.
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/AI.NavMesh.CalculatePath.html
so if i said for example
if BuildCost>Build resources = true{
...yeah forgot i was in discord and needed shift enter XD
ok, so if i were to run, in a bit of rushed code here:
NavMeshVar.BuildNavmesh();
PathVar = NavMeshVar.CalculatePath(transform.position, target.position, NavMeshVar.AllAreas, path);
and then checked that that path was valid, it should return true only when its not blocked
I'm not sure about build navmesh. What does the documentation say? It might be more performant to use an obstacle instead of rebuilding the mesh.
oh? maybe i was misunderstanding but when i searched about rebuilding navmeshes at runtime i heard that unity navmeshes were normally baked so you had to rebuild and thats the code i found in visual studio 😅
ahh, looking at this update may be faster?
They are baked. But obstacle components with carving allow modifying the baked data in real time.
ahh, and this would still cause the code to wait till it was modified till it checked the pathing?
I think there's some context missing here. They're probably modifying the surface manually.
That I'm not sure. You might need to wait a frame.
but no longer than a frame? this is the issue that caused months of dev hell in unreal i waited a frame and never thought to take longer and concluded time wasnt the issue 😅
It's hard to tell without testing. Checking the docs might reveal a way to make it sync.
ill have another looksee, worst comes to worst ig i can always retreat back into the little unreal cave i crawled from XD
was probably a bit ambitious to try returning to unity with an idea id never done before when previously it was only stuff id had a pretty good grasp on already(other than my light sensor code, still fairly proud of that one)
If you want to avoid black boxes(relying on Unity close sourced implementation), you should implement your own A* pathfinding so that you're in full control of it.
I don't think the pathfinding is gonna be a bottleneck either way. Though I guess it depends on the scope. Anyways, if it's your own implementation you can tailor it to your specific scenario to improve performance.
Anyways, back to what I said at the very start - try the simplest solution first. Forget about performance until it works.
thats fair, i guess ive just been hyper aware of needing to do things in the right way from the start since i had a bad experince with a team in the past where due to decicsions beyond my control i needed to rewrite everything id already worked on despite trying my hardest to make everything modular
Teamwork is different. You need to communicate and make sure everyone's on the same page.
very true
Is it possible to have dynamic area modifider volume? I am trying to create a realistic enemy and NavMesh Obstacle for such stuff isn't fitting, since it only carves out a chunk of the NavMesh. For my case I would like to be able to use moving objects as obstacles that agent will try to avoid, but if there is no other path, it will try to push it's way through the object, and this perfectly fits into a concept of area modifier with more cost than normal area, but I can't really find a way to make it dynamic, so are there other ways to do such stuff?
well, changing an area modifier volume cost requires you to re-bake the navmesh. maybe you could make the obstacles carve the navmesh and check if there's a path to the player? if there is no valid path, just disable the obstacle carve option.
it's still kind of a hack option as i don't think there is an easy way to achieve a better result with unity's build in navmesh.
Okay, thank you
I dont remember how i nav mashed the walls can somone help me please
when you bake, all the objects with collider get included in the bake iirc. like if it has a box or mesh collider it will automatically be detected, but idt your object/character will path through the walls or on the walls
you problably rotated the gameobject the navmesh surface is on
Thx for the help
for some reason the mash is only on one side off the wall
You'll have to create another navmesh object that's rotated for each vertical direction you want to bake
Hi there, I have done unity 2d for about 6months + I want to dabble into ml agents but I donno where to start, or if I'll fall into tutorial hell and not learn anything or if things are outdated. Any suggestions
First it would help if you start in the correct channel. This one is for AI navigation specifically.
#1202574086115557446 is for everything else, including ml agents.
As for your question, start with tutorials, but don't just copy them, research everything you don't understand. This applies to any tutorials, not just ml. And you should have understood it by now.
Rwgaeding "outdated", tutorials might be slightly outdated, especially around the environment setup, but that's where the part about "research everything" comes into play.
Any tutorial in particular ud like to suggest
Nothing in particular.
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
hi, I just saw the navigation static is deprecated, what's the alternative now to exclude a certain GameObject from a nav surface?
navmesh surface component
Hi, I'm making a navmesh generator from scratch, or at least trying to :P for now i have a simple voxel grid generator - i use boxchecks to detect voxels, raycasts to check their slope (angle from the normal to vector3.up) and capsulechecks to check if there's enough space around each voxel, and job system for optimization. result on screenshot - blue boxes visualize walkable voxels. but i have a bit of trouble understanding the next step. as we have this mess full of voxels, we should simplify it, right? i have an idea that is visualized on the second image - from this voxel mess we only take the corners (which basically means we skip voxels that have more than 2 neighbors), and then triangulate it? but i heard of something called spans - which stores data about each column. but i don't see how that would help and why my solution (potentially) wouldn't work. can someone please tell me if my way of thinking is correct or how i could fix it? :P
well, did a few tests and looks like my solution wouldn't work for non-convex shapes :(
hmm, maybe i could check diagonals too. this way i would exclude voxels that don't have a specific amount of neighbors. but i still aim for a 3d navmesh, so may someone correct me :P
how familiar are you with graph theory?
it looks like your trying to find an Euler optimisation so getting insight into that may help you 🙂
well, i do know basic graph concepts, but i'll probably have to look deeper into that. thanks for help!
bridges of konisburg 🙂
This channel is purely for AI Navigation (NavMeshes etc.), not ML Agents. Best ask in #1202574086115557446
Ok
im new in this of making games on unity and i wanted to make npcs for vehicles, the thing is i already have a controller for the car, so how do i use navmesh agent with my vehicle controller, the navmesh agent calculates the route to the target while the npc script sends input to the vehicle controller
im not sure if i explain myself very well, but i just want to use the path finding stuff from the nav mesh agent and put it on my npc
You could put a navmesh agent on the vehicle, disable agent's movement features and steer towards vectors in paths provided by the agent. This will result in pretty sloppy path following as the pathfinding algorithm will not be aware of steering limitations of the agent, but it can work quite well if you are okay with it.
Hey - very much a beginner here. Currently I am attempting to move over my AI enemy to another location, yet it is not moving correctly (or moving at all. Right now it moves based off a waypoint system (basically it checks if it is at a location then continues), but it is not moving like the others are. Im expecting I am missing something regarding the Nav Ai, but cannot figure out what. I have cleared and created the nav ai surface again, but don't know if this is causing this.
Here is the script that the nav agents follow for the waypoints: https://paste.ofcode.org/388TeSpjkpicVfjuBqHDhNs
Attached is a video of the problem. Please excuse quality.
Can someone see an issue or have an idea that I may need to do to properly reset the Nav Ai surface correctly? Please let me know. Thank you! (Please @ me if you respond, thank you).
still having this same issue, but now it is every nav agent because I am attempting to move them to a new area. Does anyone know why they dont work?
Hi, I'm trying to improve my navigation system in my procedural huge world (with chunks). I made a working script that creates the navmesh for the whole loaded world, but with new features I need smaller voxels, and many more navmesh updates: now obstacles can move -they are of course limited to X updates per second, I'm not calling the carving every update, but with a voxel size of 0.1 (from 0.25) it freezes for about 0.2/0.3 seconds every call which is really noticeable. You didn't notice it when it was 0.25.
So, I'm trying to do a local update (e.g. update the navmesh only in the local 50x50 space), but it's cleaning hte navmesh and creating a new one 50x50. Is there a way to do a "local" update of the objects?
public void UpdateNavMesh()
{
if (mergedSourcesQueue.TryDequeue(out MergedResult result))
{
NavMeshBuildSettings settings = navMeshSurface.GetBuildSettings();
Bounds finalBounds = result.customBounds ?? new Bounds(target.position, navMeshSize);
AsyncOperation carve = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, settings, result.sources, finalBounds);
carve.priority = int.MaxValue;
finishedMerging = false;
isBuildingNavMesh = false;
if (!carvedFirstTime)
StartCoroutine(WaitForCarveToFinish(carve));
}
}
This is the function that updates the navmeshdataasync. As you can see it either use the customBounds (always 50x50x50), or the default one which is 2500x2500x2500 (the whole loaded world).
I'm using NavMeshComponents
Also, I have many thousands objects loaded. Works really well, up until I need more precision
How do you guys feel about ai replacing coders/programmers anytime soon? Im studying game development right now but im a bit scared of my future as a future game dev...
wrong channel but while it's a concern to a extent i wouldn't be put off looking as a future
some jobs are getting replaced because upper management buys into the hype but ai is not in a place to replace jobs anytime soon
!collab @sturdy lodge
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
how do you keep your scenes from looking like a giant mess of invisible walls and navmesh modifier volumes?
or should i embrace the chaos?
You can disable gizmos for stuff that you don't want to see.
Hi is there an issue with navmeshsurface gizmos in unity 6 or am I doing something wrong? The navmeshsurface doesn't seem to have that blue colored mesh over any of my level's ground planes.
it looks like your gizmos are turned off
Really? But in the screenshot I've checked all
or is there another setting?
Oh ok i had to click on that main gizmo icon to activate it...
thanks that solve the issue
Hello, I have an issue reguarding the navMeshAgent, it is kind of diffuclt to describe the problem here, if anyone is open to vc with me to help, please do
Could record a video.
By any chance could you remove my educator role. I mistakenly clicked on educator when entering the server.
Hi everyone, I am implementing a cooperative multi-agent Escape Room environment using MA-POCA
The scenario:
- I have a group of 4 agents.,
- The episode finishes only when ALL agents have escaped the room.,
- When the last agent escapes, a Group Reward (+100) is assigned to the whole team
How should I handle the agents that have already escaped while waiting for the rest of the team to finish, to ensure MA-POCA correctly assigns the credit? I've read that SetActive(false) stops the agent's logic entirely, which might prevent from correctly registering them when the final group reward is distributed at the end of the episode, am I wrong?
you want #1202574086115557446
Hello, I am currently having a really strange issue. I cannot seem to rebake the navmesh in the my scene and have it register any terrain. Even a new terrain I add is completely ignored when I bake. I tested this in a new blank scene and it works, but it refuses to register any terrains in my game scene. I also tried duplicating the scene to no avail. I have no idea why this is happening. Using Unity 2022 if that helps
I solved the issue. I disabled all the other gameobjects besides the terrain and navmesh, baked just the terrain first, and then re-enabled everything and baked again
Hello everyone!
I have a question: what the heck is going on with my boss???
I know it because of the settings of my NavMeshAgent
Acceleration - 100
Speed - 100
Angular Speed - 360
Is there a solution to NOT use a Move function instead of calling SetDestination as in an example in video here?
How could I stop the abrupt pause when the enemy is under the player? Every enemy stops no matter what when the player jumps, the enemy (scrapwheel) keeps on rolling if it misses the player, but stop abruptly when the player jumps in place.
The enemy is supposed to be a fast-moving cogwheel with rough turning but big damage in groups.
my stopping distance is 0 and auto-braking is false
Hey. this is like my second ever unity project. but i thought it would be a fun idea to implement a simple enemy ai. If you've ever heard of mindustry, im trying to recreate a pretty simple version of that. i have a core, and the enemies are supposed to go to the core and destroy it. I cannot for the life of me, get the navmesh to actually show up when i generate it! I've spent like the past 10 hours on this POLEASE THIS IS A CRY FOR HELP PLEEEEEEEEEEE3EEASE
WAIT OMG SOMETHING IS HAPPENING IDK WHAT I DID BUT I DID SOMETHING AND I THINK THATS THE THING AHGAHAGHAGHGAHAGAGHAGHGahjgagh im gona tweak
im working on a car chase game with some friends and im in charge of making the cop ai for the game. ive tried using the navmesh/nave mesh agent to make them fallow the player and that works.. kinda... it doesnt allow me to apply our custom car physics the the cars. does anyone have an rescources or anything i can use the find an alternitave ?
You can use the NavMesh only for the path finding itself, and the car would be fully physics based (no NavMeshAgent) with forces applied to follow the path (e.g. calculate how much to turn, accelerate etc. To the next path corner)
I recently published a post about an alternative avoidance solution to the RVO approach used in Unity. Some of you might find it interesting. I’ve also successfully integrated it with Unity’s NavMesh for global navigation.
https://lukaschod.github.io/project-dawn-website/blog/sonar-avoidance/
Vision-inspired local avoidance algorithm for RTS agents that projects nearby obstacles into angular space and selects collision-free steering directions in real time. By reducing avoidance to a 1D angular domain, it achieves fluid group movement while preserving precise and responsive unit control.
Is there a way to check if a NavMeshLink is working? In our project we swap NavMeshes as we open up more parts of the game world (the meshes are really small). After swapping I used to disable/reenable the links and it would work. With our biggest level this approach does no longer work for some reason (it works sometimes, but not all the time). How can I check if a link is valid and working?
is there a way to generate less "tight" paths around corners
sometimes my enemies get caught on the bend in the stairs and get stuck
what it does vs. what I want
for now I'm just putting NavMeshObstacles in problem areas like this but I really hope this engine isn't being defeated by stairs
- It shouldn't get stuck if it's controlled purely by the nav agent.
- You can sample the path manually and adjust it however you want(for example, add some offset from the closest navmesh edge).
part of it could be an oopsie in my implementation because it's rigidbodies following a path
what's a good way to find "edges" in a navmesh? unless you also mean corners?
lovely
Is it possible to bake navmesh surfaces on prefabs?
Basic cube in a scene vs as a prefab after baking. Only the one in the scene gets a walkable area.
i could be wrong but i dont think the system is designed to juggle multiple surfaces in that way
you'd wanna bake at runtime after your dynamic stuff is in scene + your prefabs can use stuff like navmeshmodifiers and that one other component to manipulate how it's considered if neccasary
hi rn im trying to make an addon for a game that adds walkable npcs,
but i get a warning saying my agents aren't close enough to the terrain and i get another error for getting the remaining distance,
so the agent just doesn't work at all,
i attached my script and screenshots if anyone can help,
thanks