Hi can someone help me with ML -agents in unity the document says " LSTM models from previous releases no longer supported
The way the Unity Inference Engine processes LSTM (recurrent neural networks) has changed. As a result, models trained with previous versions of ML-Agents will not be usable at inference if they were trained with a memory setting in the .yaml config file. If you want to use a model that has a recurrent neural network in this release of ML-Agents, you need to train the model using the python trainer from this release. How do i use the LSTM any reference to using using photon code ?" Which file i need to change to add LSTM to the Model ?
#๐คโai-navigation
1 messages ยท Page 12 of 1
is there any free ai assets anyone would recommend?\
AI is a super wide term. What exactly are you looking for?
like npc for a fps game
Behaviour? Navigation?
behavior i think
Of the first one, yet again there are plenty of solutions. State machines, behaviour trees, goal oriented action planning and many more.
If it's simple ai, I'd go with a simple state machine.
Here's one simple and clean implementation that I use for simple ai.
https://youtu.be/V75hgcsCGOM
Build bots for your Unity game with a powerful but simple to manage state machine built completely in c#. Learn how to use the state pattern in unity, building an AI to control harvesting bots that could be used for an RTS, building game, shooter, or anything else. We'll dive into transitions, states, ai, bots, and how to hook it all up in a cle...
You can download the source code and use it as is, but I really recomment watching the video first.
alright thank you
A* pathfinding project? I'm using it currently
I was having an issue (Still kind of am). Left image he kept cutting through the Wall/Gap. Right image he got stuck:
Any ideas?
hard to tell from those photos, here's why my graph looks like:
my best guess is it's related to your settings for node size and character diamater
my node size is .32 and my diameter 1.41
the fact that the blue pathfinding grid in your screenshots is right up against the walls is likely your problem, and if you adjust those settings you should get something closer to my screenshot, with space from the walls/obstacles
Where do you set that up? In my case I'm using the Shape Grid option.
Like it still looks odd? Why is one side different than the other?
And what do you set pick next waypoint to? @hexed sequoia
Because he ends up doing this as well... Like.. Wut?
(Stops moving here)
not sure about the about the way point question, as for why he's getting stuck that is a bit strang e-- is the pathfinding radius/diameter equal to the collider on the object? if not that might be why
I'd check for any exceptions in console, too
I'm currently Presenting if you want to see.
Trying to debug live with my 2 friends watching lol
But yes. They match in my case.
Like it looks like its not taking into consideration that the unity is 0.5 Radius.
Or even the Seeker doesn't take into consideration its size?
(sorry gotta run but best of luck ๐)
If anyone else knows anything about it, I'd love some help. I dont get why its getting stuck.
Hey everyone.
I am trying to build a NavMesh on runtime for a tiling level which I generate procedurally. Each tile has a navmesh source which I push into a list<NavMeshBuildSource>. I then do a:
NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(bset, navmesh_sources, largebounds , largebounds.center, Quaternion.identity);
The problem is, it is not building anything. When I trace NavMesh.CalculateTriangulation().indices.Length, I get a 0.
I know I can use the NavMesh Surface component, but I want to figure out how to use the built-in NavMesh classes. Can anyone tell me what I might be missing?
Here is my code for building it:
navmesh_sources = new List<NavMeshBuildSource>();
Bounds largebounds = new Bounds(new Vector3(-1000f, -1000f, -1000f), new Vector3(3000f, 2000f, 3000f));
for (int i = 0; i < tiles_width; i++)
{
for (int j = 0; j < tiles_height; j++)
{
navmesh_sources.Add(leveltiles[i, j].navsource);
}
}
NavMeshBuildSettings bset = new NavMeshBuildSettings();
bset.agentRadius = .1f;
bset.agentHeight = .5f;
bset.agentSlope = 25f;
bset.agentClimb = 2f;
bset.voxelSize = 0.02f;
bset.tileSize = 8;
bset.minRegionArea = 0.05f;
NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(bset, navmesh_sources, largebounds , largebounds.center, Quaternion.identity);
Debug.Log(nmd); ->traces NavMeshData
Debug.Log(NavMesh.CalculateTriangulation().indices.Length); ->traces 0
I am guessing the indices length would be >0 if it built anything 
thanks in advance
ps: also tried: NavMesh.AddNavMeshData(nmd); with no change in outcome
hi there @severe moth i could be wrong here, but i don't think each of your tiled pieces needs it's own navmesh surface
you just need one, maybe on an empty game object, and tell it to rebuild once your level is completely loaded
thanks @fringe crag. Let me ponder this a minute, but, from what I understand, I need to define a volume for each source, then either use CollectSources which pushes all geo in a volume into a list of sources to build them into one mesh, or push them into a list and pass that to BuildNavMeshData. If it required one, I don't see why it would require a list.
my setup looks like this btw:
each tile having its own NavMeshBuildSource with shape and size set accordingly 
ah a buildsource, i'm unfamiliar with that
i just have 1 surface for my entire level, and call .BuildNavMesh() on the navmeshsurface
when it needs updating
hmm, that sure would work with one mesh.
I am referring to these btw:
http://47.94.147.94/unity/ScriptReference/AI.NavMeshBuilder.BuildNavMeshData.html
http://47.94.147.94/unity/ScriptReference/AI.NavMeshBuildSource.html
let me ask a bunch of dumb questions, usually when the navmesh is built and you have a source selected it'll show you the blue mesh in the scene view. do you see that appear?
yeah nothing appears in the editor ๐ฆ
that + navagent complaining is how I confirmed it wasn't building prior to trying triangulation.indices ๐
right
since i have no experience with the navmesh builder and build sources i can't really comment. But i do know that you could programmatically set a singular navmeshsurface and build once your level is finished "assembling" (or just let it calculate for everything visible if that is everything). and it doesn't require any of the builder components
you just set it to use mesh renderer components, or colliders to do it's surface building
you could try it out in the editor first to confirm that it connects your tiles correctly before coding it all together
otherwise good luck! (i've definitely been having issues with these component based navmesh scripts)
thank you ๐ This doesn't (supposedly) use NavMesh Surface from what I understand. I will update if I can figure anything out.
CollectSources does exactly that btw, you can specify what you want to collect NavMeshCollectGeometry.PhysicsColliders or meshes, and it puts it into the source list to be built.
yeah will try some in-editor stuff to explore some more.
thanks again Andrew.
allow me to ask one more basic question, i see in the docs that any meshes you're using need to be set to read/write (i think by default fbx's are readonly)
are you using imported fbx's / objs?
that's a good point, I am using the primitives in Unity so no fbx's in there.
btw, switched to this instead of pushing in the sources to the list:
Debug.Log(navmesh_sources.Count);```
does populate the list, but still doesn't build.
When I trace the NavMeshData's position, I get the correct position (largebounds' pos), but when I trace the sourceBounds, I get 0 on all fields -> meaning it didn't build
ok I am getting bounds info + indices.length on NavMesh.calctriangulation() now, so it is building something believe ๐
what I changed:
Bounds largebounds = new Bounds(new Vector3(0f, 0f, 0f), new Vector3(3000f, 3000f, 3000f));
it was:
Bounds largebounds = new Bounds(new Vector3(-1000f, -1000f, -1000f), new Vector3(3000f, 2000f, 3000f));
not sure if I clicked anything inbetween, but I think this was it 
it is built

thanks for the pointers @fringe crag
ah so instead of passing the center + extends you were passing a start corner + end corner?
glad you got it
...so...removing the navmesh isn't instant. every new room I am generating, I am rebuilding the navmesh, but it always includes the last navmeshdata's contents in it. so room 1 generates navmesh1, room 2 ends up with navmesh 1+2, room 3 gets navmesh 2+3 and so on. took me a while to realize it takes a second to flush the former room's data. introducing a delay after NavMesh.RemoveAllNavMeshData() fixed it. adding here for future prosperity.
on the left hand side: removes navmeshdata, gets the new one, rebuilds navmesh but it ends up with both the new one and the previous.
on the right hand side: a .5 second delay is introduced.
hope this helps someone, I was too slow to get what was going on heh.
also do let me know if you know a way to flush it faster ๐
worth trying https://docs.unity3d.com/ScriptReference/AI.NavMeshDataInstance.Remove.html
Not sure if it'll have the same problem, haven't had the chance to test, but might be worth checking out. Does the nav data dump out on the next frame, or is it an async task?
If it's always on the next frame, you could have a bool that cycles notifying your system when the new data is available.
Just spitballing some ideas ๐
yeah I tried that as well, same results ๐ thank you
could simply be async
For some reason, when I go up to an AI or an object they appear, but when I am an inch away or any further they disappear. https://streamable.com/3cjboz
The zombie doesn't run to the player. I'm thinking it has something to the walkable area on the zombie?
@limber glen And I want you to follow out crossposting rules. Don't crosspost questions.
There are so many questions and so little answers๐
im using the A* pathfinding package, is there any built in function that prevents the enemy from seeing the player through walls?
@ruby birch Out of the asset's scope, but you should be able to determine reachability
You probably just want to roll your own or get some visibility setup
yep thats what im working on
I don't want to break any rules, but I have a problem I posted in general-code over an hour ago. I think it might make more since here since it involves the NavMeshAgent component. Can I re-ask that question here?
Yes, you can ask questions again once reasonable amount of time has passed. Moving the question here after waiting for an hour is fine.
Guys I chose the object with Navmesh and hit bake but it still wont owrk
any ideas why?
share some more info: GO screenshots of the scene view, hierarchy, inspector, navmesh baking settings.
Oh dont worry I fixed it by repeatedly smashing the bake button, sorry for not telling in advance
And crashed my unity a few times
guys how many methods are there in coding ais?
You should expand on what you are actually asking. It's not an exact science coding behavior. There are as many methods as you can imagine.
well, for example, I want to know which is the best and most efficient way to code an AI
so it wont result in a block of mess
maybe one that has mulitple behaviour trees?
or suitable for that
It's situational to the purpose. Find Pluggable AI course on Unity Learn. It describes a neat way how to do that for an RTS style with Scriptable objects, for example.
right, thank you.
In the current project I'm working on I use both a NavMeshAgent for path finding and a CharacterController to control movement of an AI. The problem is the object's transform.position now returns the NavMeshAgent's position instead of the objects actual position. Is there a way to disable this without disabling the NavMeshAgent?
Okay I think I figured it out. Even though the navmeshagent's updatePosition and updateRotation where set to false it was still trying to fight with the CharacterController for control over the players position. So in update the transform.position returned the navmeshagent position, and in fixedUpdate and visually transform.position was returning the CharacterController position. I can work around this, but is there a way to disallow the navmeshagent from controlling the characters position?
Just an update, I think need help with this anymore. I think I'm just gonna ditch the navmeshagent and get the path directly form the navmesh.
Hello, i need help on a specific problem, to which google could not provide me a satisfying answer. I have multiple agents using navmesh, hundreds. When i tell them to reach a destination they glitch together until reaching it then rest. I want a typical RTS behavior here, which is try to reach the point and then come to rest, without forcing into each other. I wanted to use the builtin navmesh for optimization and ease of use, but it seems complicated to prevent glitches between agents. I tried some flow field pathing too but huge grids come at a huge cost and there is no tutorial to my knowledge about how to optimize this.
Has anyone any experience with multiple agents pathing and able to help me with it ?
Is there something that would cause a NavMeshPath variable to delete itself? I have a NavMeshPath variable that I instantiate in the Start method. But its null by the time CalculatePath gets called.
Does anyone know how to make people roaming like in GTA
just animate them
But how to make them move random pos
use blender and import them into your unity
Hmm
i have a person on discord who is experts at these things
Why didn't I got this idea
do you want his id
Add a script that set different target position every few sec.
What exactly is the problem?
I wanna make people they should roam here and there
Then what I said. Just assign different random destination for the agent to follow.
I wanna do this for the jam
And I wanna do one quick method
Animation is better ig
No, it's really faster to just write a small script...๐
I"m so confused why it acts like this
I obviously have mesh for it to walk to, but it runs around all crazy
the link when single point / wide was also acting different with a different camera position
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class PlayerMovement : MonoBehaviour
{
[SerializeField]
private Camera camera;
private NavMeshAgent agent;
private RaycastHit[] hits = new RaycastHit[1];
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
}
private void Update()
{
if (Input.GetKeyUp(KeyCode.Mouse0))
{
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.RaycastNonAlloc(ray, hits) > 0)
{
agent.SetDestination(hits[0].point);
}
}
}
}```
is my point to position method poopy?
Here's the surface settings. I'm following a tutorial step by step and getting absolute trash behaviour from the navmesh.
shit like this being a constant really makes me want to give up.
Feels about as useful as pissin in the wind.
I don't understand what the problem is from your video or your explanation.
I see the agent navigating the navmesh properly
sorry Obs hid cursor.
Anytime I clicked a ledge pretty much it went to the ground
when you see it jump on the little ledge and back down it was supposed to jump up to the next
First debug the raycast and make sure the first hit point is the one you're expecting.
so just draw a gizmo at the point?
or a debug ray
okay
honestly I'm having a super rough time today and I just can't handle doing anything like I'm literally sobbing.
I had enemies and animations and attacks and health and knockbacks in a different project and this tutorial had something I wanted to learn and I was stuck on something so I just deleted it and now I can't basic things to fucking work
Then take a break. It's not your job, is it?
No it's not. I sat here for half an hour and feel much better. I have circle gizmo drawing on click, but it doesn't look like it's on the surface of an object but just ... in the screen space.
share code and a screenshot
@tardy junco gizmo is drawing fine. Idk why but in playmode navmesh looks like its floatin. Scene view it's on the ground.
public class PlayerMovement : MonoBehaviour
{
[SerializeField]
private Camera camera;
private NavMeshAgent agent;
private RaycastHit[] hits = new RaycastHit[1];
private Ray ray;
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
}
private void Update()
{
if (Input.GetKeyUp(KeyCode.Mouse0))
{
ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.RaycastNonAlloc(ray, hits) > 0)
{
agent.SetDestination(hits[0].point);
}
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawSphere(hits[0].point, .1f);
}
}```
Here's the movement code
I've noticed depending on camera rotation the navmesh link doesn't want to work at all.
Hmmm
I dont really recommend the inbuilt navmesh stuff tbhj\
it actually created more problems than it solved for me tbh
suggestion then?
needed a lot of little hacks and stuff
a* path finding project
try the free version first
you do have to watch some of his vids, look at his demo scenes and read some stuff
but the behaviour is better and doesn't screw up imo
@fickle ravine I just can't understand how absolutely every single ai.navmesh tutorial I've done has produced constant errors
Every video things are dandy
Every attempt I make absolutelyt nothing works
honestly the unity nav mesh is bad
i have released 2 games with it
i they have a lot of hacks
Donno man. I've only used it for simple stuff, but it never produced any bugs for me.
I don't see the free a* thing you're talking about
it used to have a free version let me check
downloads here
@tardy junco idk, it doesn't seem like it makes sense. I'm doing step for step the things in this series and literally nothing about it works right https://www.youtube.com/watch?v=aHFSDcEQuzQ
In this video you'll learn what NavMeshes are, how to get the NavMesh Components from the Unity Github (which is what you should be using!), and cover the basics you need to know when setting up your first NavMesh.
We'll also go over:
โซ How to make Click-to-Move on a NavMesh.
โซ How to make an Enemy follow a Player on a NavMesh.
โซ How to ha...
like. I follow verbatim and no luck.
i could get the inbuilt stuff to work
but they used to fall through floors and stuff
๐
think that is still a possible bug in grand battle
Well, this is not really the default navmesh stuff.
my main problem was actually swapping between player controller and nav meshed ai
that usually when they fell through the floor
Navmesh components are not included by default with unity and you need to go to github to get it, which should already make you aware that it's not a completely supported feature.
It is an experimental feature yeah
It still doesn't make sense that it'd function the way it is imo
I bet you just missed something that causes all the issues.
I've gone through the first three videos three seperate times now, there's absolutely no way.
@tardy junco Actually if you'd humor me, the videos are like 10-15 a pop. If you wanna give it a go and test my sanity I'd appreciate it lol
Cause idk. I feel like a crazy person sometimes
I will give it a try if I remember it when I'm not working.
I just don't completely understand the issue.
baking multiple levels and links wouldn't work
following the exact instructions in the videos
Wanna upload your project somewhere, so that I can also see if I can find a solution?
Sure I can do that in a bit too
Is there the right place to talk about NavMesh ?
What do you need to know btw? I've used it in the past, but I didn't do anything complex.
Basically Ive made a procedural dungeon generator
I'd like to find a way to bake the nashmesh surface for the whole generated dungeon using code
The dungeon is made of prefab rooms
So you need to bake at runtime?
Yeah. Right after the dungeon is generated
Guys how do I make the AI go to the nearest patrol point?
@obtuse solar did you upload the project somewhere?
@wind plinth navMeshAgent.SetDestination
@polar shadow to bake at runtime you can add a navmesh obstacle to your object, and programmatialy enable carve, this will rebake the local space of the navmesh that needs to around your object
cc: @obtuse solar
how do I make my ai choose a random target between three identical prefabs
it only chooses the first in the list right now
I just discovered brackeys made a video about runtime navmesh generation ๐ง
what are you supposed to put inside SetDestination() ?
a position doesnt seem to work
can you get a point to aim for with it, without using raycast or any form of hit ?
A transform's position should work yeah
Yeah whatever vector3 you can feed in. You could even make a new vector3 based on current one + 1 unit ahead for example, to make it go forward indefinitely ๐ dunno what you want ๐คทโโ๏ธ
you could sample the navmesh for the closest position on the mesh to be safe
I want my enemy to chase the player once it has triggered a "chasing" state @real sonnet
So ive made a raycast that turns the chasing state to true if it hits the player
However I can't seem to update the SetDestination() using player.transform.position
{
RaycastHit hit;
Debug.DrawRay(transform.position, transform.forward * 20, Color.red);
if (Physics.Raycast(transform.position, transform.forward, out hit, 20) && hit.transform.name == "Player")
{
Debug.Log("Player spotted");
chasePlayer = true;
}
if (chasePlayer == true)
{
agent.SetDestination(player.transform.position);
}
else agent.SetDestination(transform.position);
}```
i've checked if the raycast works as intended, the enemy indeed turns into the chasePlayer = true state. But it doesn't move.
player is a reference to my player game oject
Wht is player ?
Woopsie my phone didnt scroll till the end sorry
At first glance I don't see whats wrong
(just beware you never set chasePlayer to false ?)
If the agent doesnt move, could be something else not correctly setup
Did the agent ever move ? Like if you give him some position further away without condition does it work ?
Assuming you set the reference correctly
if i set it to hit.point
it moves towards me
however once i leave the raycast it will stop following me
i'll try setting up canChase to false
Hum I'm not sure then. Did you debug the player pos ? Maybe the player is on a position the agent cannot reach ?
Shooting in the dark here
player.transform.position returns (0.0, -5722.6, 0.0) @real sonnet
why is that y coordinate broken
I fixed the coordinates or player.transform.position by correctly assigning my player object. However it still doesn't move
when its set to "chasePlayer == true"
tweaking my navmesh surface settings and agent made it work.
my (i hope) final issue it those little holes in the mesh
also when the enemies aren't chasing me, they arent turning instantly. How can I fix that ?
Could somebody please tell me why my navmeshes are now baking with treetop areas included in them? I just want the ground level for my navmesh. How can I only use the ground/terrain level of the navmesh and get rid of the rest?
Hello, does using the static method NavMesh.CalculatePath have any pre-requistes? Like, do I need to make sure having done something so it works?
I'm asking because I'm trying to use it and the path that it returns is always invalid
I tried looking for a solution but I can't find anything
navMeshAgent.CalculatePath does work though
So I don't understand why it wouldn't
Or is there anything that could prevent it from working properly?
@broken jay maybe you bake it for agents which are higher than your tree tops so they can't get below, and thus the navmesh prevents them to do so
kinda looks like you didn't rebake the mesh after changing your level.
Make sure that both points are on the navmesh and that area mask is correct.
Both points are indeed on the navMesh, does the Y axis matter, because the points might be slightly under?
if it's under, then it's not on the navmesh
use sample position to get the closest point on the mesh:
https://docs.unity3d.com/ScriptReference/AI.NavMesh.SamplePosition.html
NavMeshHit hit;
if (!NavMesh.SamplePosition(origin, out hit, 100, NavMesh.GetAreaFromName("Walkable")))
{
Debug.Log("no available origin");
return;
}
if (!NavMesh.CalculatePath(hit.position, targetPoint, NavMesh.GetAreaFromName("Walkable"), _path))
{
Debug.Log(_path.status.ToString());
return;
}
This is how I'm trying to use it
the code is failing in the SamplePosition that I recently added per your suggestion
which of the 2?
the origin one
Oh lol, there's only one sample position.
Yes and it's returning false
Try debugging the origin point with a gizmo or a raycast.
You're probably feeding in a very wrong position
Also try using NavMesh.AllAreas for the mask
The origin is the transform.position of a character that is standing on the NavMesh, so I can't imagine how it would be wrong
Can you share the part where you get that origin?
public class AIPathingManager
{
private NavMeshPath _path;
private bool _hasPath;
public Vector3 currentTarget { get; private set; } = Vector3.zero;
private Queue<Vector3> _cornerQueue;
private Vector3 _currentDestination;
public void CalculateNavMesh(Vector3 origin, Vector3 targetPoint)
{
if (!_hasPath || targetPoint != currentTarget)
{
NavMeshHit hit;
if (!NavMesh.SamplePosition(origin, out hit, 100, NavMesh.AllAreas))
{
Debug.Log("no available origin");
return;
}
_path = new NavMeshPath();
if (!NavMesh.CalculatePath(hit.position, targetPoint, NavMesh.AllAreas, _path))
{
Debug.Log(_path.status.ToString());
return;
}
currentTarget = targetPoint;
SetupPath();
}
}
public void CancelPath()
{
_cornerQueue?.Clear();
_hasPath = false;
}
void SetupPath()
{
CancelPath();
_cornerQueue = new Queue<Vector3>();
foreach (var corner in _path.corners)
{
Debug.Log(corner.ToString());
_cornerQueue.Enqueue(corner);
}
GetNextCorner();
_hasPath = true;
}
private void GetNextCorner()
{
if (_cornerQueue.Count > 0)
{
_currentDestination = _cornerQueue.Dequeue();
_hasPath = true;
}
else
_hasPath = false;
}
public Vector3 GetDesiredDirection(Vector3 currentPosition)
{
if (_hasPath)
{
Vector3 dirVector = _currentDestination - currentPosition;
if(dirVector.magnitude > 0.5f) return dirVector.normalized;
else
{
GetNextCorner();
return GetDesiredDirection(currentPosition);
}
}
return Vector3.zero;
}
}
Here is the whole class
I create an instance of this class in the character that I want to move using NavMesh's pathfinding
I call "CalculateNavMesh" to get a new path, and "GetDesiredDirection" to get the direction that I have to take toward the next corner
Where do you call CalculateNavMesh? What do you pass in as the origin?
I pas as the origin the transform.position of the controlled character
I call CalculateNavMesh on FixedUpdate
Mind showing that part of code?
Try adding a debug ray like that and see where it draws:
if (!NavMesh.SamplePosition(origin, out hit, 100, NavMesh.AllAreas))
{
Debug.Log("no available origin");
Debug.DrawRay(origin, Vector3.up * 10f, Color.red, 3f);
return;
}
Wait
With NavMesh.AllAreas I am getting a result
Seems that the problem is with GetDesiredDirection somehow, because I'm getting Vector.down as a response
Doesn't seem like you set _hasPath to true when you get a new path
Nvm
That piece of code is pretty messy. And considering it's run every frame we don't know what the hell is going on with it.
I'd try putting a lot of debugs everywhere to see how the code executes.
Fixed it
Didn't know that the first point you get is the origin point
Or well, the position in the navMesh under the origin
Thanks for the help
im baking it through code at runtime
well, it looks like you just placed obstacles there
the only thing I have is an invisible enemy spawner
it doesnt have the obstacle component
or it may be the agent itself... Do I have to bake every frame to cover spaces that were covered by an agent ?
no
The agent shouldn't create holes in the navmesh
In case you ticked it as navigation static, you should untick that.
hey i'm having a problem for a RTS-like movement of my units. When i click somewhere my units go there and form a nice group which is good (pics below), but when i click somewhere else the group "explodes" and the units lose consistency in the group. I use rigidbody.MoveTowards to move the entities i can't set the velocities directly because units would glitch together. Does anyone know which technic is usually used for group consistency in RTS ?
look into boids and flocking steering behavior
they explain it here mate
Pre-Order now at: http://store.uberent.com
Segment 1: Jon Mavor and Kevin Francis talk about planet generation and the deferred rendering engine. In-engine demo.
Segment 2 (00:24:15) Jon and Elijah Emerson talk about the navigation, and flow fields. In engine demo.
www.twitch.tv/uberchannel/c/2057442&utm_campaign=archive_export&utm_source=ube...
thats industry leading RTS pathfinding approach
have fun
thanks i'll look into your ideas ๐
Will check that. Thanks. Also do you know if there is a way to not get my player pushed by enemies moving towards it ?
I turned the enemies collider into a trigger as a band aid but I would want those enemies to body block the player without pushing it away
nice i already use flow fields
ok well your flow fields need to be modified
by the units
to prevent clumping
you can kind of cheat
and modify the flow field by the destination of the units
its a trade off, for correct behaviour tho
when my units have a direct line of sight on the target position, they just go straight towards it
this allows precise positionning
and prevents from calculating another flow field
set stopping distance or target destination just before the play maybe๐ค
well you need to just rely on the flow fields guidance and not do that outside the range of a unit of measurement
it cant lerp to a node more than grid unit away from it
because that will ruin the path finding
when you get within the granularity of the flow field you can lerp for smoothness, but thats more an animation thing and is in a different system tbh
this issue is my grid squares are pretty huge, and so is the granularity, because i'm calculating the flowfield over a 256 * 256 grid and i need it to be performed on one single frame. Using jobs and burst i got it to take less than 15ms, even less when built
i can't really divide it into chuncks since i aim to something like starcraft, where during end game you will completely fill the map with units anyway
so
you mean non blocking ?
when you click move
they move instantly in that direction
but they do the flow field calculatiopn
in the background
on multiple threads
definitely dont want your pathfinding to be blocking
oh, no can't do that if there is an obstacle in front of them they will take the wrong direction
especially in an RTS
so
you just need to correct fast enough
for it to not look stupid
you have like a 10 frame limit
even can extend that to 30 frames
things dont move that fast
even delay the initial move a few frames
for the calc
starcraft does this
yes indeed the issue is choosing the right direction, and that is pretty hard
oh i did not know starcraft did this
you can either wait
for it to get the right direction
or go in the wrong direction
and turn around
both are fine
it wont be the wrong direction most of the time
i was waiting for LateUpdate to give it a little more time, but yeah i might need to wait a few frames
yeah definitely dont rely on a frame
its complicated but
you can do a lot of guess work in between to smooth stuff out
maybe i can use the builtin navmesh to choose the direction, they go very fast
that sounds about right
use a lower resolution nav mesh
to discover direction
while you wait for further instructions
from the higher resolution one
oh that's a way simpler idea
i'll juste use bigger granularity then calculate more precisely
thanks for the idea
I have a kinda large question, but what method do you think games like Monster hunter, dark souls, the witcher, etc... for their boss AI ?
they most probably use state machines
You know, the usual big monster/creature that "randomly" choose an attack depending of the distance, number of player surrounding them, etc...
I also instantly think FSM with some hard coded conditions to choose their next move/attack
But I dunno if there are other "common" methods
no because
it needs to use random
to not be predictiable
which is when the host decideds
and sends it to everyone else
and thats the problem
A condition can be randomness
AI is not predictable
and you need to SYNC it between everyone in the game
that means the host decides what the ai does
and everyone else just "plays" it
especially because
everyone is on a different location
on everyones computer
so what does the AI use for the position of player 3?
it uses the hosts knowledge of player 3 position
which was sent across the network
Yes
which is why games need to be host dictated
Host can be a dedicated server "simulating" the fight I guess ? for MMOs
for mmo
they have a seperate server yer
that tells everyone what is going on and where everyone is and what spell the monsters used
very server heavy
dont recommend making mmo
Yeah XD
That's another level
No wonder why it cost so much to keep mmo alive
say they are 1mb packets
thats 2.4 gigabytes a second
the server is sending
not happening
they will lower the packet size or the players allowed on that server etc
that bandwidth doesnt even exist atm
๐
They try to do as much as possible client side
Andd probably only "validate" inputs/outputs from players
I won't
will take you a few months to get right
few month is generous
i am a generous guy
XD
And for the AI itself, what type or architecture do you think is used ?
Not in MMo
In solo/room limited games
For this type of bosses (yeah we derived a lot I realize it now XD)
i use like a naughty dog uncharted approach
i have state machines compromised of states that are comprised of behaviours
and the behaviours are as granular as move to x,y,z
so you can do some pretty interesting stuff
well i tried double checking but I don't understand why I still have those holes in
when i look at my room in prefab mode i see that little cube in the middle that might be the issue. However I do not know where it comes from
okay. My parent "inner walls" object had an obstacle component i forgot to remove... sigh
I am using A* pathfinding for a 2d game, but i am not being able to apply forces to the AI, is there a way i can apply forces to it and make it accelerate?
Like, script forces are not working
Disable the pathfinding agent, apply force, enable it back after the agent moved by the force. Or just rewrite the way your ai agent controls movement. ๐คทโโ๏ธ
Anyone know why this is happening?
Sry for not answering, I see, I think that's close to how I imagine that type of AI then. Thx for the conversation !
what is happening?
well, it seems like the nav mesh agents, when I hit play, will fly alway
I cant change the position back to 0 0 0 cause if I do so they will just continue their journey across the Pacific Ocean by adding another 10k into x y z
I donโt know
Don't ping people with unhelpful comments. You don't have to post if you can't offer help.
Hi, I am working on navmesh agents and wanted to have same game mechanic as of Voodoo Castle Raid. I am not able to understand how the path finding and grass deletion is working in this. For reference please watch the video. TIA
https://www.youtube.com/watch?time_continue=20&v=El5YZJiJl30
One way you could implement it is by baking the navmesh at runtime.
Yes I have researched that but it looks expensive.
The area with the grass would not have navmesh, but as you remove the grass, additional area for the updated navmesh frees up and the npc move there.
Never know until you try it.
right. So on touch up I have to bake mesh again.
Ok I ll try this first.
I also found this technique. just not sure how to use this with Navmesh Agents
https://www.youtube.com/watch?v=EygJSTL-B-k
The unity package below contains the source code:
https://drive.google.com/open?id=19eiMaUVOx6km7xX82jN0cpkUljsVU3Fq
Please LIKE the video and SUBCRIBE to my channel if you find it useful.
If you discover any bugs, please let me know.
Package with new approach ( I have not implemented attaching colliders yet) : https://drive.google.com/open?id...
and one more. Can we create navmesh links dynamically ?
Looks like mesh edit at runtime. It might actually be heavier than rebaking the navmesh.๐ค
I believe so, yeah
never used them though, so you'll have to research that.
cool. Thanks for replying. If something works out I will post here. ๐
Suppose there are 100 units on one side and another 100 units on the other side of a field, how can I calculate the closest enemy for each of them without lowering the fps too much? I tried to follow some youtube tutorials on them but havent found one that is good. So I tried to use kd-trees and knearest algorithm, but I don't know if that's the right way to do it.
pls I need some advice on this
if the units are close together and you store them in an ordered fashion, you could run your chosen search algorithm on only the 4 or 5 units around the current unitโs index in the array instead of filtering through the whole array of units
you could also run an algorithm on all of them once at the beginning to assign a unit for each to kill if youโre ok with it only killing its assigned unit and no others
How can I make people like in GTA vice city people moving at random positions and spawning at random positions
Couldn't even find a good tutorial on YouTube
It's too simple for a tutorial. You simply spawn(either instantiate or grab from a pool) an npc in a random location on the Navmesh. Then assigning random destination on a Navmesh every few seconds or so. Of you want them to move along roads and stuff, you'll need some kind of waypoints system, then it's the same as before, except you pick a random waypoint.
But what if the assigned unit dies? Or if the assigned unit suddenly goes away from him and there are other units closer to him
yeah that makes it trickier, i guess my method wonโt really work
have you tried raycasting? that might end up being faster, idk
like raycast in a few forward angles every once in a while and pick the closest one but if thereโs nothing, turn the unit a few degrees
https://www.youtube.com/watch?v=nzzS40XHWA8
I think this will help you
Place 300 pedestrians in a city in Unity using UMA, Dungeon Architect and some open source code.
Want to give your cities life? This really simple technique will ensure your city is bustling and what's more it won't cost you a penny. Use any assets you already have or use the open source UMA and a simple open source spawner and AI script.
00:...
Hey, How do you make NavMeshAgent effected by physics? I added a rigidbody but when he's supposed to stop at certain distance it stars to glitch like jitters and shaky, and also apparently they can't be effected/knocked back by an object launched with AddForce
Whats your current code?
Because youre saying its supposed to stop at a certain distance
it's in the inspector "Stopping Distance"
I think you have to have Navmesh Agent Stopping distance > Navmesh Agent radius
right
Yeah that is possible, but I fixed it, I just changed the Kdtree script a bit
awesome
A NavMeshAgent generally can't be affected by physics. You will need to detect a collision, disable the Agent, and let the rigidbody take control. When the AI is ready to move again, turn the NavMeshAgent back on. While the physics object is being controlled by the agent, make sure isKinematic is on for the rigidbody, and off when the physics sim is in control.
I figured it out, thanks anyway
anyone have a problem where the AI would just flies away after baking? It's annoying and I dont know how to fix it
now it keeps flying up, anyone knows a good alternative to Navmesh? I'm done with Navmesh
Did you try recreating your scene till the problem appears or disabling stuff till the problem goes away? So you know what causes the problem
How to prevent nav mesh obstacle from pushing entities and only carving?
Thanks!
Hello I think this belongs here? im using A star pathfinding for my AI and i wanna be able to set the grid to be local meaning i can easily move it and not have it world space, does anyone know how to do this?
Hi, im doing a my final project for university and was wondering how i should do the AI. Its a grid based tactic game like Front Mission or Final Fantasy Tactics.
The professor told me to investigate the different types of state machines but i only find info about FSM. Are there other types or its okay with FSM?
Hey, I'm pretty new to the Unity AI stuff and could use some help with something.
I'm trying to find the point closest to the agent(enemy), but still connected to the player
Hi, I think you can use Navmesh raycast
https://docs.unity3d.com/2019.4/Documentation/ScriptReference/AI.NavMesh.Raycast.html
@kindred lily Thanks, I'll look into it!
@kindred lily Got it working using this! Thanks!
well I tried closing and opening unity and somehow it work
thats also often a good thing to try
I've actually been having an issue with this. I can't reference or assign NavMeshSurfaces at runtime. I forked the correct solution. Any clues?
I've never used it actually. Only the default navmesh.
Ah gotcha
Yeah I can drag or click the dot but nothing populates
Searching by NavMeshSurface on start doesn't assign anything either
But the code recognizes the class reference and commands
Can you drag it in?
are both objects in the scene?
Yeah
You sure about that?
100%
not a prefab?
Nope
And the object you're dragging actually has the NavMeshSurface component?
Yeah. My suspicion is that I installed the packages in a way that was incorrect but I can't figure that out just yet.
Hmmm...
In order to get the NavMeshSurface code references actually working I had to install the GitHub package
But in order to get the rest I had to install the Unity experimental package
Now, I did the second one first, and then installed the GitHub package after which actually let me reference navmeshsurface in code
So my suspicion is that the GitHub package doesn't recognize the Unity Experimental package NavMeshSurface as being the same
And that the Unity package supercedes the Github package's
Did you try installing it following the instructions on this page?
https://docs.unity3d.com/Packages/com.unity.ai.navigation@1.0/manual/index.html
Yes, that was the first thing I did
But after installing that package, even after using the using UnityEngine.AI include, I could not reference NavMeshSurface in code to bake at runtime
It didn't recognize NavMeshSurface as a valid class in code. Only as a component.
If both the serialized field and the component on the object are of the same type, it should work.
It could be a problem with your ide then..?๐ค
@willow vault if you click the script field on the component(in the inscpector), where does it take you?
and if you go to the implementation in the script with the serialized field?
Oh I'm starting to see an issue
which share types but don't seem crosscompatible
the correct one seems to be the second
probably because I installed both packages?
Perhaps
I can populate the public variable now, so that seems to have fixed it
Thanks for being patient with me haha
I'm relatively new to the NavMesh system but I understand it to some extent. In terms of creating smart AI, is it best to use some combination of both NavMesh Agency and AnimationControlled Behavior States to create good AI?
In a lot of the research I've done, I've seen three approaches: NavMesh, hard coded states and detection systems, and Behavior States. My assumption is that some combination of all of them will create the smartest enemies with the best animation systems but I don't know if there some "best" approach in Unity.
I'd use the animator for animations stuff only. For behaviour I'm using a simple state machine implementation mostly hardcoded. I don't have very smart ai though. The npc have several simple states: pedestrian(follow waypoints), attack, combat movement and some abilities state.
Unity does not have a default "ai" implementation, so you've gotta do it yourself.
Makes sense
Oh yeah thank you, no worries, I've watched that one before!
Just trying to figure out the best practice for my game haha
Hello everyone. I created walk system based Navmesh. So when I click the ground player moves. But also when I click another object that high from ground player moves again
Can i ignore the move when clicking this object?
I try the obstacle but isometric camera angle is problem for this. I think I need to check if clicked ground or another object. Any help?
this is the move script
Do you have your clikable_ground mask set up properly?
Umm, is it bake in Inspector window? If yes, i can see blue texture on ground, so works fine. Problem is object higher from ground. Bake wonโt paint when I set obstacle or non walkable ground. But when I click on object player still moves because of camera angle
I mean I canโt click non walkable area (bottom of object) because of camera angle
how can i make him rotate and try to come to me because he only attacks if im in a straight path with him
private void Chase()
{
if (!_navMeshAgent.pathPending && _navMeshAgent.remainingDistance <= 2f)
{
NavMeshHit hit;
if (NavMesh.SamplePosition(_targetPlayer.transform.position, out hit, 20f, _navMeshAgent.areaMask))
{
_navMeshAgent.SetDestination(hit.position);
// Set blend tree speed variable
_animator.SetFloat(_animIDSpeed, _navMeshAgent.velocity.magnitude);
//Debug.DrawRay(hit.position, Vector3.up, Color.blue, 1.0f);
}
}
}
Hello i follow a tutorial and someone can explain why use SamplePosition and not directly SetDestination for move to the target ?
what are you trying to achieve ?
it's for vertical sampling
SamplePosition , calculates nearest point without considering obstructions.. you don't really need it just keep , _navMeshAgent.SetDestination
obstructions?
Hi there, simple question. Is there a way to make navmeshagents follow a sort of curved path to the destination and turning slightly overtime, rather than turning sharply on the spot and then moving on the path.?
Reduce agents rotation speed
i am trying to make AI enimies in my game but none of the things i have tried work does anyone have a code i can try
plz help
what did you try and why did it not work?
as i have never made an AI before i follwoed this tutorial
FULL 3D ENEMY AI in 6 MINUTES! || Unity Tutorial:
Today I made a quick tutorial about Enemy Ai in Unity, if you have any questions just write a comment, I'll try to answer as many as I can :D
Also, don't forget to subscribe and like if you enjoyed the video! :D
See you next time.
Links:
โคNavMesh Components: https://github.com/Unity-Technologie...
i dont have the code anymore as i deleted it when it didnt work
What didn't work?
wait i have script
i didnt delete it
it move or attack the player
@tardy junco
So what's the issue?
it dosnt move towards the player even when player is in chase range and when play is is attack range it dosnt do anything so it just dosnt move or do anything at all
plz help
Add debugs to your state functions to see what state your ai is in.
No that doesn't work, the object still moves on the path, it just moves backwards and then rotates slowly
You might need to write a custom agent then
Ah okay thank you
I think I just need to move the object forward and slowly rotate it to face the target destination, then use SetDestination
I just tried this, works perfectly. You haven't done something correctly, careful copying code you don't understand because you won't know what to look for
did you set the player tag like with your code ? "player" with the same no cap P
q
I was guessing his ranges (walkRange, sightRange, etc) were still zero in the inspector
oh yeah good catch, the inspector values for ranges might be 0
Hey everyone!
Trying to get my navmeshagent to 'Pause' at a destination before continuing to the next destination in my array. But I keep getting the error:
IndexOutOfRangeException: Index was outside the bounds of the array.
NPCMovement1+<GotoNextPoint>d__5.MoveNext () (at Assets/NPCMovement1.cs:35)
Here's my agent code:
https://paste.ofcode.org/ZJ7GUqGEyMKEU7qPBr9Ewz
Any ideas?
Huge thanks!
if (destPoint == points.Length)
array length = 1, destPoint = 0, what will happen?
Then, it should +1 to destPoint?
most people do length -1 but its kinda the same yea
Ah, so because you include 0 in the array .. if the array length is 10, the destpoint would have to equal 9 to be the end of the array?
yea
Thanks! No more errors, but my agent is now having a fit deciding where to move ๐ onto the next issue!
one problem at a time ๐
Delete?
Implement a damage system, when damage > health, destroy(gameObject)
The order of conditions is important.
"do something else"
else if (inside outer ring)
"execute an action"
else
Default behavior```
can't help without seeing the code?
Good point
but I think I'm just going to rework the code entirely, I realized there's actually no need for circles at all
I'm probably just going to rework the game entirely, I don't think the code is good, and I don't want my mistakes to come haunt me
Colliders and tirggers would be the easiest, the best efficent way Imo is learning how to use Raycast, specifically a spherecast or boxcast would work better in your case
I'll search these up in time, I'm now learning some of the basics tho
raycast is basics to a lot of things and interactions
{
Click();
Move();
//Destination();
}
void Click()
{
if (Input.GetMouseButtonDown(0))
{
DaRay = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(DaRay, out Hit, Mathf.Infinity))
{
if (Hit.collider.tag == "bldg")
{
MovePos = Hit.collider.transform.position;
Debug.DrawRay(DaRay.origin, DaRay.direction, Color.red);
Destination();
}
}
}
}
void Destination()
{
if (Navi.destination != MovePos)
{
Navi.destination = MovePos; //new Vector3(MovePos.x, this.transform.position.y, MovePos.z);
gameObject.SetActive(true);
CanMove = true;
Navi.isStopped = false;
Debug.Log(Navi.isStopped);
}
}
void Move()
{
if (CanMove)
{
Navi.isStopped = false;
}
else
{
Navi.isStopped = true;
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "bldg")
{
CanMove = false;
gameObject.SetActive(false);
}
}```
So navmesh is pathing but not moving?
Any ideas?
Iโm currently trying to give my NPCโs a ray casted vision cone, but I am at a loss. Iโve tried many different methods, but it seems as if it doesnโt work at all or they can always see everything no matter what.
If anyone could help me put a working script together, Iโd appreciate it.
This is what Iโm trying to achieve but obviously CANT
Share your code.
Would if I didnโt delete it. Let me see if I saved it anywhere, I usually back up all of my code.
The way I do it usually is either distance check detectable objects each frame and add them to a list inRange or add them OnTriggerEnter with a trigger sphere with a radius equal to visibility range. Then iterate objects inRange every frame or a two and raycast to them. Then add/remove them to/from inView list based on the resulst of the cast. Of course, you'll need to make sure that objects exiting the view range are also removed from the inView list.
My enemy ai isnt attacking, taking damage and the Layermasks created wont show up
Please post questions in one channel at a time. #archived-code-general
i made an AI for my game but it dosnt follow the player or attack the player i followed a tutorial as i have never made an AI before and last time i tried it didnt go well here is the code
all the enemy does is walk around
but dosnt do any of te other stuff like attack or chase the player
that is what the script looks like on the enemy
all it does is go to the walk points but it dosnt chase or attack the player
pls help
this is the tutorial i followed
FULL 3D ENEMY AI in 6 MINUTES! || Unity Tutorial:
Today I made a quick tutorial about Enemy Ai in Unity, if you have any questions just write a comment, I'll try to answer as many as I can :D
Also, don't forget to subscribe and like if you enjoyed the video! :D
See you next time.
Links:
โคNavMesh Components: https://github.com/Unity-Technologie...
all it does is patrol
Did you set the Layer masks properly? And is the player on the correct layer?
oh oops
fixed that
i keep making dumb mistakes like
that
half of my errors come from spelling mistakes
lol
srry
@tardy junco
You shouldn't be able to make spelling mistakes. If you do not have autocomplete ensure you have your IDE configured using the instructions in #854851968446365696
ok
thx
everytime i watched a tutorial to do something i didnt know how to auto complete didnt work
thx
Did it end up working?
I watched that same tutorial yesterday and i had the same problem
Do you mind if i ask what exactly you did to fix it?
sure
Thank you
Yes
and also did you put the whatisplayer layer in the player and in the scirpt in the enemy
??
like that
I added the layers but i didnt touch the script
Yes i have it like that
and do you have the whatisplayer layer on player?
No
Alright thank you so much
Ill be working on my game later tonight so ill tell you if it works then
ok
So I recently watched this GDC talk https://youtu.be/Qq_xX1JCreI?t=1974 about behavior trees and specifically at this point the speaker introduces the idea of using a hybrid system that combines behavior trees (good at providing the directions for a specific behavior) with some other management structure, like a FSM or GOAP, to improve the implementation of AI and the behavior trees by cutting out repetitive trees and providing some closed loop structure when appropriate for the behavior trees. My question is has anyone applied such a system and was it more beneficial for both your programmers and designers as things went on? Would there be a threshold of necessity where you can just get away with a behavior tree before wanting to considering using a hybrid system? I'm really interested in implementing such a hybrid system for some AI I plan on having fireteam/squad behaviors and various combat and idle states.
In this 2017 GDC talk, Bobby Anguelov, Mika Vehkala, and Ben Weber outline core principles to get the most out of your behavior trees while avoiding common issues.
Register for GDC: https://ubm.io/2yWXW38
Join the GDC mailing list: http://www.gdconf.com/subscribe
Follow GDC on Twitter: https://twitter.com/Official_GDC
GDC talks cover a rang...
Does anyone have a code snippet for generating off-mesh links at runtime?
I have a number of libraries I've stumbled across with less-than-stellar documentation and tutorials and am having trouble getting my agents to behave as expected after reworking my runtime baking.
The agents are getting stuck on the new surfaces, and not navigating obstacles correctly.
i have this code for the enemy in my game and it throws a sphere prjectile at you but i was trying to figure out how to make them despawn because the becomes alot of them and they can get laggy how do i make them despawn after like 20 seconds or somethin
here is code
or here
pls help
how do i make the projectiles depspawn
Despawn enemies or projectiles?
the projectiles
They should get destroyed after 5 sec according to the code.
it is wierd though they dont
Are you disabling the script or something?
Ah, it should be Destroy(rb.gameObject, 5f)
Was that part in the tutorial?
the tutorial didnt even have despawning but there was so many i needed to try find out how
Do some beginner tutorials on unity learn. You seem to be missing some basics. Doing random tutorials on YouTube is not gonna help.
They assume you already have these basics.
@karmic knoll Hey! I did not try implementing such idea myself, but I plan to do it next year, probably
Regardless of that, there is an article on GameAIPro about Final Fantasy XV, which did Behaviour Trees + FSM. I'm sending it here in case you didn't have a look yet:
http://www.gameaipro.com/GameAIPro3/GameAIPro3_Chapter11_A_Character_Decision-Making_System_for_FINAL_FANTASY_XV_by_Combining_Behavior_Trees_and_State_Machines.pdf
Hey, I'm struggling with an AI concept right now, if anybody can help I'd greatly appreciate it.
Blue represents navmesh and red equals walls
My AI can jump between navmesh areas
Now my issue is I need to have the enemy jump to the edge across rather than the one closest to the player
Because right now they get stuck
did you try using NavMeshLink?
Just to be clear, you want them to jump to the green dot?
He wants them to jump to the end of the straight-down arrow on the left, but they keep jumping to the end of the diagonal arrow and get stuck on the wall, if I understood correctly
I believe NavMeshLink is the way to go
Is it possible to make them jump from the start of the navy mesh link and then land at the end rather than walking over it?
Anyone have experience with using Prefab objects with NavMeshSurfaces on them?
I'm instantiating a "Room" for my procedural generation, the prefab for which I have pre-baked
I then spawn the enemies and activate their agents on top of that surface
However, after moving to this method, the AI stopped working properly and no longer detects my player, and the navmeshsurface seems to be baking invisible geometry
this is how it looks in prefab view (cannot view NavMeshSurface)
and here's what shows up in the main scene when I instantiate
(the inside of the box)
What in the heck are those big blue planes out there?
can i change walkable area clamp ? i mean like in the picture
also why those agents tryin this instead of using crosswalks from anotherwhere
every walkpoint is reachable with crosswalks
Hello i'm new to Unity, me and a friend are working on remaking pacman from scratch as a challenge. I'm using A* as an AI. I have the A* scripts all apart of the Enemy Parent object. What i need help with is keeping the rotation of the child object "straight." In this video the Pac Man turns upside down at times. Tried looking through the internet for solutions but couldn't really find one that worked for me.
til all about Eulers, and transform.Rotate and transform.localeulerangles
and i learned what i was doing wrong!
Any system that is dogmatic about its abstraction (i.e. a pure BT) will eventually run into complexities when the (part of the) problem doesn't fit the abstraction. A good BT implementation will allow you to insert FSMs and arbitrary code ad hoc to fix/circumnavigate such inefficiencies. These can be black boxes with project specifix semantics that designers can use just like select/sequence/monitor/...
I wanted to make a topdown shooter with car ais similar to what the first gtas were, for the civilian ai I've got everything working but I can't get the cars working for the love of me.
Can't find how they originally did it either so if you guys have any info or insight on that i'm taking it
For once they didn't use unity๐
haha
If you want to use the navmesh with vehicles(vehicle colliders), you'd need to write a custom agent, that will control the vehicle based on the path, instead of controlling the transform directly.
I tried doing that to no avail, handling the turning and especially trying to correct after a crash/getting of course was a nightmare.
Also placing nodes for every lane that a car can take is pretty exhausting so i wondered if there were other methods
maybe a navmesh could be enough, is there something special for vehicles ?
Hello guys. I tried to create a shooter ai buh it was a dead end for me
hey guys i was just making enemy follow the player(the capsule) and i set animations and scripts and this happened. enemy keeps running in a spot but i wanna make it play idle animation when it stops help me please.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ai : MonoBehaviour
{
// Start is called before the first frame update
public Transform target;
private NavMeshAgent nav;
private Animator animator;
void Start()
{
nav = GetComponent<NavMeshAgent>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
nav.destination = target.position;
animator.SetFloat("Speed", nav.velocity.magnitude);
}
}
here's the code
HELP
Probably an issue with the exit transition on the animation
So what should I do
What does you animator look like?
the scene one is idle animation
Seems like that should be correct. The agent may return speeds that are non zero but close to zero. So if you're in that blend it should probably be close to Scene. Have you tested it against blend values near zero? Or is there any states outside this that may be doing something?
thanks the problem solved
i was just working with the wrong animations :///
A question regarding the Navmeshagent: Is there a way to make it drift less past corners?
So it always kind of walks in a straight path from corner to corner
It often overshoots around corners which isnt what I want
Ok turns out I just had to bump up the acceleration a ton
sup everyone!
I have been doing a lot of reading and I feel rather torn. I am new to unity and I need to make AI.. I was thinking I do simple patrol from point A to B and if the player is close enough enemy will attack the player.I then started reading up around UtilityAI but I can't find solid working examples.
What are your thought about AI? Should I try and implement Utility as a newbie or should I just stick to simple a to b
Stick to state machines or behavior trees. Still need to learn about them, but it's way simpler than Utility AI.
It doesn't sound like you need a complex system like that for just 2 states.
In fact state machines and behavior trees might be an overkill already.
I would like to have AI that would walk about, chase and attack player, run if damaged enough and self heal..
with that said
the more simpler AI I will start with but I will research state machines.
Hoped to get people's thoughts on this. My game involves base building-ish mechanics. you can build platforms, and stairs leading up to higher platforms. these platforms are 100% user placed. I'm currently using the component based navmesh system, and upon exiting "construction mode" calling rebuild mesh if any structures changed.
as the scene gets more complex the little "hitch" of rebuild can be pretty noticeable, especially when i set my voxel size to production quality
i was hoping i'd be able to precompute navmeshes for platforms and stairs pre-build and seamlessly just place them, but agents don't know how to traverse the separate surfaces without navmesh links
anyone have thoughts on how to optimize / rethink the way i'm handling this situation?
Also i've asked this many weeks ago, but NavMesh.CalculatePath() just does not work with component based navmesh system. Always returns false. ๐ข y tho
Not necessarily targeted help here, but when the situation is changing that dynamically I find a regular grid based nav mesh is easier to deal with. It's not compatible with unitys stuff but there are some solutions (also a* on grids is pretty straight forward)
normally i would agree, players also have the ability to decorate with oddly shaped decorations
so doing broad collision detection is pretty important too
i might have to break up each "floor" into it's own navmeshsurface and make stair objects navmeshlinks. might help break up the recalculations
Newbie here to most things game development especially AI and coding. I'm working on a small game with wave based enemies. The idea is that enemies spawn in a room with two exits and use either one. They travel a short distance before settling on a random spot in front of the player and attacking from there. They never attack the enemy in close-quarters.
I've used the tower-defense tutorial by Brackeys, but it didn't work the way I hoped.
I have code that adds a story to a building. that story has a navmesh. the 5 first stories prefab have their navmesh, but after that all the other stories prefab dont get the navmesh. any ideas why and how to fix pretty please? ๐
Hey, so I've got a scene where I have an opening in a wall. After baking the navmesh, the opening is unable to be walked through, any ideas why this is?
Probably because you don't have any surface outside..?๐คทโโ๏ธ
haha, thanks for that got it now ๐คฆโโ๏ธ
do i only need C# to make an mlai?
cause most tutorials uses both C# and python
Python is just used for the tools. You don't need to write python.
can somebody help me with how to setup an navmeshquery filter area mask?
i tried this: public int areamask = 4<<6; public UnityEngine.AI.NavMeshQueryFilter filter;
then apply the areamask to the filter an then make use of the filter within the UnityEngine.AI.NavMesh.SamplePosition- function
i also created a "new filter"if the samplePosition function was called, but its not working
i only can use 1, or large values like 320 (areamask)to get positions
areamask 4 till 6**
i dont want to sample other areamasks, just 4 till 6
โ
Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=uDYE3RFMNzk
Let's look at Layers and Bitmasks to see how they work. We can manipulate Physics interactions and what a Camera sees.
If you have any questions post them in the comments and I'll do my best to answer them.
๐ Subscribe for more Unity Tutorials https://...
you need to setup areas
and then connect the objects to the areas-> navigation static
go to the objects tab and then select a gameobject to set the desired navmesh area
NAVIGATION STATIC MEANS IT GETS BAKED
I'm having an issue with Unity NavMesh, can somebody please help me?
An agent is supposed to get as close as they can to their destination if it's on a disconnected part of the navmesh.
And it works properly when the platform the agent is on is small in size like this.
Hold on, making another diagram
But when the plane the agent is on is large in size, the agent just completely freezes up if it can't reach the destination
It's causing some real issues on certain maps in my game and I have no clue how to fix this
All the code is doing is setting the destination of the agent
logic error
?
something in your script is messy, or your agent is baked in a wrong wa<
y
@lucid kayak show your controller
Let me make the simplest script I possibly can and see if it still happens
reproduce is always the best approach
I have determined it is caused by setting destination every frame
If I want to make an agent follow something that moves, how should I set this up if I can't set the destination every frame?
I don't see anything about this mentioned in any documentation, so I'm pretty lost on how to progress from here
The agent essentially rotates a bit before moving to the destination
This wouldn't be that big of an issue if it SetDestination wasn't being called frequently, but since this agent is supposed to be following the player, it basically never moves
since SetDestination, in my case, is called every 5 frames
I'm making a turn-based ai system, but I dont know how to begin. Any leads are helpful
just call the function repetetive
but its working for me without extra work
i am not sure i understand
Unity uses a lot of existing tools for training, which are commonly managed with python. You need to have python environment for running the tools, but defining how rewards are handled and control over training sessions is scripted in Unity with C#.
Installation guides go through the steps to setup the python environment
Can anyone point me at some good open source AI frameworks? Ideally something optimized for 3d navigation / object avoidance? Bonus points for one that doesn't require custom monobehaviors be assigned to each world object in the scene. Something similar to this ideally: https://www.youtube.com/watch?v=cWiKMl7blgw
Here's a couple of example scenes from our upcoming 3D-package!
Unity Store: https://bit.ly/32ikzfs
Unity Forums: https://bit.ly/2NHCV5U
Twitter:
https://twitter.com/polarith
Instagram:
https://www.instagram.com/polarith/
Facebook:
https://www.facebook.com/polarith/
Does anyone knows an asset for Unity for HD Earth rendering usable from a Space point of view? I've seen a lot of really cool assets for "ground to sky" images, but I need a "space to ground" point of view. I need it to create a dataset generation pipeline for an AI algorithm that does cloud detection
hi may i ask if anyone knows why navmesh agent is bugging like the one in the video? https://www.youtube.com/watch?v=ba2SaWcg0ZI
i checked the navmesh already if there are any bumps or something but that doesnt seem to be the case
@dense sparrow Is there a reason you are cross posting these?
hey so im having a issue to where unity wont bake a navmesh on to my custom table
It is set to static
Is it at least 2 units wide?
Hey i actually figured it out. the navmesh was still way too big which is what your getting at im pretty sure
Yep
Yeah i got excited and sent everywhere, then unity's bots kicked me in the back haha
I have had a problem before where having many agents active at once would make them all jittery
the solution was to disable auto braking
not sure if it applies whatsoever to your situation
but who knows
Anyone know or have a tutorial on how I can have an AI in a Driving vehicle?
thats a very broad question
Google as a lot to say about that, I'm sure
Alright, I've asked for help on this time and time again, and in multiple servers, I genuinely don't know what to do anymore and I'm about to completely give up on this.
Unity's NavMesh has been giving me so many issues that I'm about to just write my own solution, but I'd still rather avoid that if possible.
Right now, I'm having an issue where agents will rotate before moving, but only under specific circumstances (when standing on an unreachable part of the navmesh, or after warping the agent).
Please help, I'm completely stuck at this moment and members of my team are waiting on me.
https://youtu.be/3J5O2SZpaB0
As you can see in this video, the cube (being an agent) is fine following the player normally, but as soon as I jump up onto the other platform, it starts looking back every time I set it's destination to the player.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Test : MonoBehaviour
{
NavMeshAgent agent;
void Start ()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if(Input.GetKey("e") && !agent.pathPending)
{
agent.destination = new Vector3(Player.localPlayer.transform.position.x, transform.position.y, Player.localPlayer.transform.position.z);
}
}
}
I made a script as simple as I possibly could to make sure if it was my enemy component's fault
It still happens
This is what the navmesh looks like
@lucid kayak It's not terribly uncommon to write your own navmesh agent while continuing to use the pathfinding implementation of Unity.
@molten sequoia Biggest hurdle here is the lack of an async calculate path function
https://www.youtube.com/watch?v=7RKL7mAzAe8 my AI is clipping through obstacles and I've done everything I can to prevent so. Even increased the AI agent's radius, setted the obstacles as not walkable, and given the obstacles a navmesh agent obstacle with crave component
Hey, I'm currently developing a VR Colony type game. (think Rimworld, but with VR capabilities) I'm currently trying to figure out the AI. I'm not going in depth as Rimworld, but you can assign each human one job. (EX: Lumberjack - chops wood and then carries the wood to storage) If anybody could point me in the right direction or recommend a asset please let me know!
Did you check the experimental pathfinding API?
https://docs.unity3d.com/2021.1/Documentation/ScriptReference/Experimental.AI.NavMeshQuery.html
Hey everyone, does anyone know if its possible to have a NavMeshAgent run in edit mode? I want to have one navigate by pressing a button on a custom editor (while the game is not running)
I'm getting the following error when calling setDestination()
SetDestination" can only be called on an active agent that has been placed on a NavMesh.
The agent works fine when the game is running
Probably can't use NavMeshAgent. I would try the experimental API as linked above and replicating the needed NavMeshAgent functionality.
No idea if it actually works though
Thanks
Can someone point me to a visual editor for behaviour trees, preferably integrated into the Engine??
Hi guys ๐ Im making a 3D (top view) racing game and now Im trying to add some bot cars. For the AI, should I use ML-Agents try to implement my own AI?
So i put the NavMeshAgent on my player object, and NavMeshObstacle on a rotated cube like on the image below, and then i pressed "Bake" in the Navigation tab. The navigation mesh looks correct, and my player follows it perfectly on the terrain, but not on the cube. It just stops or weirds out whenever it's nears the edge of the cube.
Anyone know how to make my player walk up the cube correctly?
Is there a workaround or trick to make ai pathfind underwater, or flying?
unless you tell it to do something differently underwater, ai doesn't know what water is and won't do anything different so i'm not sure what you mean
I can handle the movement handling when underwater
Just the pathfinding part that im not sure
Can navmesh be used underwater? Like an underwater tunnel for example
I guess what would work is a waypoint type graph. But im already using navmesh
Unless mixing graph type is a thing?
Are there any good free behavior trees out there?
PandaBT
@vast viper does that one have a visual editor?
The "editor" is just a notepad. If u make change and save, u dont have to recompile so u can continue playing while iterating
The state visual of Panda is like this in the inspector
(from the docs)
http://www.pandabehaviour.com/?page_id=23
If u mean visual editor as in node based, no it doesnt
Just bcoz i'm using it
I never tried any node based BT tbh, but visualization wise i'm fine with text based like this
I'm a coder, so
I don't like node based coding so i thought why would i like node based BT if there's a text based/indent style
sure, I get your reasoning
@vast viper ended up using this:
Get this free behaviour tree editor asset for Unity by following the link:
๐ https://thekiwicoder.com/behaviour-tree-editor/
Support this channel:
๐ https://www.patreon.com/thekiwicoder
Previous Behaviour Tree Videos:
โถ๏ธ Behaviour Trees using Graph Builder (Part 1)
https://youtu.be/nKpM98I7PeM
โถ๏ธ Behaviour Tree Editor Styling using USS style...
which seems to be working great ๐
Looks good
I might give that a try too
I had to modify the code a bit to be able to work for my 2D project, but other than that I'm currently happy with it
Kinda a shot in the dark here but I'm trying to set up the Polarith AI "Perception Pipeline" and my dropdown menus are not populated like in the documentation, if anybody knows what I've done wrong it'd be greatly appreciated
I figured it out so I guess ill post the solution forum style. if you leave the AIM environment labels blank it makes them unselectable in the dropdown so a name is required.
Hello. I think, questions about Navmesh go here, right?
I have a terrain and road going over it. I try to bake navmesh for a road, but I don't want my agents venture off it
In some places when terrain gets close to road I get artifacts like this
what's wrong?
How do I specify Navmesh generator to use only that Road object?
Road is defined as single object
Ah.
I get it
I removed Navigation Static checkmark from Terrain
I have added it to Road and specified it as walkable
for a racing game, should I train the same AI (using ML-Agents) on different tracks?
how do you think, will my agent get past roadblocks?
Question do i need linked lists to make an adjacency list or can i use regular lists
@wraith basin To answer your question. I have used BehaviorDesigner in the past but plan on using NodeCanvas in my current project.
I should probably clarify that I've done a fair amount of research on this by now and only decided to ask because none of the solutions I found actually fit my purposes.
the simplest and most prominent one that I keep running across is the "unity tanks" thing
Alright, are you able to clarify what exactly you are asking/wanting help with?
(Glad to hear you already did research before asking!)
basically how bad of an idea would it be to reflectively grab each behavior's name when scripts are compiled and use those as options in a dropdown for a MonoBehavior
i 100% overcomplicated things trying to explain LOL
that's on me though, i'm stressed and burned out working on like 6 projects simultaneously
brain mush
Oh, that all? You can just use TypeCache.GetTypesDerivedFrom<T>() in editor.
nobody fucking told me that TypeCache was a thing before now holy shit
you're a lifesaver, i've been doing that shit manually
i'm gonna cry lmao
I work with reflection almost constantly (for an unrelated work project) and it's even worse than Python
LOL. Feel free to ask in #โ๏ธโeditor-extensions for things related to custom editor windows and inspectors and such.
i'm gonna look into BehaviorDesigner and NodeCanvas rq since you mentioned them
on name alone, NodeCanvas sounds like something I could use
yeah, these both look solid, but I'm broke
I would use NodeCanvas, it also supports FSM. BehaviorDesigner is a bit nicer imo for behavior trees, but it was made for quite an old version of Unity originally and imo it shows.
for context I'm in college and don't get paid enough
Yeah, NodeCanvas looks much nicer and it seems more flexible
supports dialogue trees as well as behaviors
Any ideas on how make a flying AI with root motion? I have issues getting the model to move on the y axis
For context, itโs an animal flying.
What's the problem? It's not moving on Y, or it's moving unreliably?
Probably both your script and rootmotion are overriding each other. Make sure you're using lateupdate, you might need to set the script order.
If you don't need the rootmotion y value, just set your own. If you do, then you will need to read it out so you can check what point in the animation you're at and add the right amount to your value.
... or you could just make new animations of it flying up and down, and blend those in so rootmotion can control the vertical height.
Sorry to ask, but how come I would do that on the late update? Also, I am using the Kiwi coders blend tree add on, and it doesnโt use monobrhavior
For now, Iโll try getting a blend going, thanks
Hey, so how would i go with creating a AI for driving that track? Most turtorials ive seen have used the waypoints but in my case i dont think they will be helpfull as there are randomly generated obstacles (see images). The obstacles could be generated in any form. Now how should i implement smart driving for the car?
2D or 3D?
Maybe try pathfinding?
Just make a path that they always follow
Hi is there a way to generate a grid of points on a navmesh surface?
2D
Well its The obstacles are randomly generated
Is the path always the same?
If it is, you can put multiple waypoints across the breadth of the track
Is that a word?
Anyways and then disable waypoint is theyโre inside an obstacle
Does anyone use Astar Pathfinding project Pro?
So every obstacle blueprint would have a waypoint and than just enable disable?
Makes sense
I am having a problem with The ai script i usecan anyone help the ai just looks in the direction it originally saw the player when the player enters the attack range can anyone help? https://hastepaste.com/view/COTakWfvpt
here is problem
can anyone help?
it works in one of my levels but not in the others
also it dosnt chase the player
I see sausages and tomatoes. Where are the enemies?
the orange things are the enemy
they only look that way
never mind i fixed
Ok imma start using ai guys but I am wondering what is the best way to hold previous information. So my character tells the ai my name is โsosoโ then next time I play it will know my name. I do not want to use player prefs at all just wondering where to save this info. I basically wanna evolve the ai. I worked with ai a bit but not in unity so ๐ค
De/Serialization and save to file. There are different ways to serialize your data: Json, binary, xml. Choose one and look up tutorials on them.
Thanks a lot
Hi everyone, I need a bit of help. I'm using navMeshAgent.CalculatePath to see if an agent can go there without any issue and to get the resulted path for making a "navigator". The problem is that CalculatePath is returing true even if it's impossible that he can go to destination, even if destination if very far away from last path point.
I can check the status to be NavMeshPathStatus.PathPartial but the world I'm working on is pretty big, so sometimes the status is partial even if he can move there.
So my biggest problem is that status of path is partial if the destination is impossible or if the destination is far away. How can I check if destination is not reachable?
Hello! Does anyone have any suggestions for tools/workflows to clean up navmeshes of all the unwanted/small/detached islands, without having to go and manually change every renderer? (not to mention the renderers that cannot be changed because they are merged with ones that need to be walkable)
Check the Navmesh cleaner asset on the asset store.
void Start()
{
ai = Instantiate(obj, spawnPos, Quaternion.identity).GetComponent<AI>();
ai.SetupAI();
ai2 = Instantiate(obj, spawnPos, Quaternion.identity).GetComponent<AI>();
ai2.SetupAI();
}
bool frame = false;
private void Update()
{
if (!frame)
{
ai2.gens = ai.gens;
ai2.neurons = ai.neurons;
ai2.Mutate();
frame = true;
}
}
and my AIs have a same path, but idk how it happens cause ai2 is mutating and it may have dif gens than first ai, but if i'll look in inspector first ai have same gens and neurons with second ai idk how it's working
so that is indeed the best shot ^^ I hoped there was another way, but that seems good enough
anyone know some 2d animal ai?
what do u want the animal to do?
u still there?
you sorta need to be more specific
what do you want it to do? wander? chase? run from predators?
wander
i'll see if i have one
https://www.youtube.com/watch?v=aEPSuGlcTUQ found this video
Here's how to make super simple wander AI in Unity! It's so easy even a beginner can do it!
is 3d, but easily translateable to 2d
anyone know how to update the centre of a graph in a star pathfinding?
Is there a way to partially regenerate a NavMesh? I want to be able to create obstacles at runtime, but I dont wanna fully regenerate my navmesh, only the area where I created an obstacle
Why not use carving on nav mesh obstacles?
How would that work Perfomance wise? The obstacles would 95% be static, like walls, fences
Should be relatively fast. How many obstacles do you create/remove every frame?
Probably < 1? Player should be building most things per hand, enemys will also be able to build, but certainly < 1
Then it's not a big deal