AI mesh tutorial

Mortus

Veteran
Best answers
0
Hello, I was looking through a forums searching for any AI mesh tutorial or at least some info but didn't found much. Maybe my searching skills are not so good but anyway, I decided to write one.

I was thinking about placing this thread in the main mod development forum but then decided that here's a better place for it. Custom settlements is one of very few mods where AI mesh editing skills is very important not only for mod developer, but to other users, because they are actually creating scenes for it. I noticed that many people don't understand the AI mesh concepts, some of them don't know how to use it correctly. It took some time for me to understand some basics about it so I'm sharing this experience with you. Please note that almost everything mentioned in this tutorial is consequence of my own observations and testings and not everything could be actually right.

Also, please excuse my English, if you want to make this tutorial looks more literary, feel free to PM me, I'll edit the post gladly.

There's also one more thing to mention before we start. Many people have their game crash when in AI mesh edit mode. There is few ways of preventing this if you have the problem. First, always edit AI mesh in "Scene Editing Mode (Cheat)", you can enter it by pressing "Enable Settlement Edit Options" while camping on the world map, the option will appear then in the settlement menu. If it won't help, then try not to move the camera while in AI mesh edit mode, switch to Object Edit or any else, move the camera, then switch back. That helped me for some time, the game didn't crashed not once, but then something changed, I'm not sure what exactly, and crashes returned. If nothing helps, try overwriting one of Native settlements with your scene (don't forget to edit scenes.txt) and edit AI mesh in Native. Maybe there's something in this mod causing the crashes, I'm not sure, but it helped for me.

Part 1. AI mesh basics.

I think I won't stop on how to enter AI mesh editing mode and any basic controls of it, it's very similar to another editor controls. You can check for info about it in "Settlement Scene Making Guide" sticky thread by wickedshot. Also, in part 2 of this tutorial I'll give an example with some of the functions explanation.

So what is AI mesh and how it works?
AI mesh is a grid used by NPC's to find a way from their location to their target location. For example, if NPC at point A wants to go to point B and there's no straight way there, he'll bump into building/fence/whatever is located between A and B and will stuck there forever. But if you use AI mesh, NPC won't use that straight path to reach destination, instead, he'll search for the shortest way within the AI mesh ignoring everything else.

Important note
All faces of the AI mesh should be interconnected to work properly. That means you cannot create mesh inside the building, then another outside, don't connect them and hope everything will be OK. Also, they must be actually connected to each other, not only placed really close. Here's some screenshots.
Right, NPC's will pass there:
Wrong, NPC's won't use this entrance:
You can connect two different faces with "fill" function while editing in vertex mode.

It is important to cover as much of the places where NPC's could walk as possible with AI mesh. Here's some examples of good AI mesh placement (screens taken from Native scenes):
Note how AI mesh is located on the stairs:

Try not to use difficult patterns while placing your AI mesh. I believe that AI mesh build of squares is generally good. Don't place too big faces, try to break them to several smaller ones. Also, don't use too many small squares, I think that can slow down the game maybe. Plus, placing big faces in one part of scene and small ones in another could result in unpredictable consequences. Here's an example:
I've placed 30 and 31 entrypoints to the point A and 32-39 to the point B. NPC's have two paths to reach from A to B as you can see. And as you can see, they chose path 2 because they think that it's shorter. And it's actually shorter in AI mesh means because there's fewer faces in it than in path 1. Try avoiding that in your scenes.

Part 2. AI mesh placement in constructions.

Let's get to some practice at last.

I've got a scene with AI mesh over the terrain here and want to place a castle on it. So I'm placing "castle_f_gatehouse_a" and switching to the AI mesh edit mode.
Right now, I need to delete faces that are under the castle so NPC's won't try to go through it's wall. Pretty easy way to do it is to select one face, then click "Grow Selection" button few times for all the faces you can't see under the castle will be selected, then deselect faces you need to keep. At that point you'll see that:
Now, delete selected faces and move remaining faces' vertexes closer to the building:
(maybe it's not the best way to design mesh and you should had added some more faces to fill the remaining space but it's pretty easy so I'll stick to it for now)
You'll want NPC's to go through the gates, right? You need to place AI mesh inside the entrance then. But you don't have enough vertexes to make a pass, switch to edge mode, select edges close to the entrance and press "Subdivide" button. The result would be something like that:
Now make the same at the another side of the gate and move the vertexes to the pass:
Select the edge that's closest to the pass and press "Extrude" button, move the new created edge further to the pass, adjust it's size, make the same at the other side:
Switch to vertex mode, select all 4 vertexes that must be connected and press "Fill" button:
Congratulations! You've finished with the easy part. Try to do it more accurate than I did though so NPC's won't stuck at the corners.

Now you need to make mesh leading to the roof of this building, subdivide and extrude another edge, I won't repeat that in details, that's what you want to see at the end:
Extrude the edge near the door two times, make sure that it's not wider than the entrance so NPC's won't stuck, also check it's z-coordinate, it must be on the floor, not under the ceiling.
Select two edges facing to the ladders, extrude each two times, move new edges so it looks like that:
Select, extrude, move, select, extrude, move, I'll stop at the moment edges will reach the top step of the first ladders:
You can notice that I added some new faces on the first floor at that point too.
Now you'll want to make a turn, extrude another edge, switch to the vertex edit mode and select two vertexes on the different corners:
Press "Connect" button, you'll see a new edge connecting selected vertexes, now delete face that's inside the wall so NPC's won't try to go there:
Move vertexes, extrude, extrude again, you know how to do it already, make your way to the top of the tower (don't forget to use "Fill" to connect faces coming from different ladders):
I'll skip the remaining process, don't forget to make the same operations with another entrance (this tower have two of them). At the end, place entrypoints 30 and 31 on the top of the tower and 32-39 near it's entrance, add some prisoners to the settlement and check if they can get to the top of the tower. If they stuck somewhere - you'll need to edit mesh there. It's important to add AI mesh to every place where NPC could possibly go. One can follow you in the battle and end up at the top of some tower without AI mesh. If that happens - he won't be able to return back neither other NPC's will be able to find him and kill.

That's a final screenshot I made when all (half actually, I didn't yet added AI mesh to the another entrance) the work is done. Try to test with slaves every pass that you've made (that's what they are for after all).

That's it for now. I hope this tutorial was useful for someone. Feel free to add something, I'll edit this post to make it more informative. Hope there was not too much images and it was not too detailed.

I was thinking about adding part 3 - AI mesh in cities, do you think it would be useful or is there nothing to actually talk about? Anyway, please leave your comments on this one and maybe one day we'll make this tutorial really good and worth reading. :lol:

P.S. MANY travellers came to my village while I was making this tutorial:
 

Diavolo

Knight
M&BWB
Best answers
0
really great tutorial, made me understand a bit better what are smart ways of making things look good.
One thing Ive had problems with is the fill option. I know that one has to select more than one vetex, but I just cant do that. Whenever I select one my previous selection gets unselected again.
How do I select many points at once? (vertexes)
 

Liquidninja

Knight
M&BWB
Best answers
0
Amazing! The Join Vertices, connect, subdivide and extrude explanations really helped me a lot! You pondered if you should write more, and to that I say: if you do have time, please do! :eek: This has been immensely helpful (and actually encouraging, now going back to edit my settlements doesn't seem so daunting anymore - I have your guide to help me :smile:).

Re: P.S. You mean a lot of clones visited your settlement while you were writing the tutorial :razz: Seriously, they are all quintuplets or something.
 

Mortus

Veteran
Best answers
0
Thanks for your support everyone. I'm a little busy right now, but I hope I'll have more time at the end of the week and will write part 3. Gotta experiment with different layouts before it though.
 

wickedshot

Sergeant Knight
Best answers
0
The problem with crashing may have had to do with events that happen.

You are probably better off with the "Edit Scene (Cheat)" rather than the "Ride towards settlement" option.
 

Chammadai

Sergeant
Best answers
0
wickedshot said:
The problem with crashing may have had to do with events that happen.

You are probably better off with the "Edit Scene (Cheat)" rather than the "Ride towards settlement" option.
Which is available only once you turn the cheats on in the camp menu on the main map.

Anyways, great tutorial. Will work a bit on my two cities to include the meshes, probably this weekend. Danzig in general needs some correcting in more than a few places but now it will be much easier to make it a better city.
 

Mortus

Veteran
Best answers
0
wickedshot said:
The problem with crashing may have had to do with events that happen.

You are probably better off with the "Edit Scene (Cheat)" rather than the "Ride towards settlement" option.
I'm absolutely confused with those crashes now. Was editing mesh in Native for a while, no crashes, then I changed back to the mod and there were no crashes again in like 2 hours (I was moving camera all the time without disabling AI mesh mode). Then I loaded scene in Native again and crashes had gone. All the time I was editing without any prisoners or peasants.

I never tried to edit in "Edit Scene" somewhy, it may actually help. Thanks for the advice, I'll try it next time.
 

Diavolo

Knight
M&BWB
Best answers
0
yep, just enable editing, go to camp and press allow editing or what its called, and then go to the settlement and press edit settlement(cheat) just like normal editing.
Then you press edit AI mesh or what its called, its one of the options similar to edit ground texture or edit objects.
 

Adorno

Bedroom Assassin
Duke
WBNWM&BVC
Best answers
0
About crashes: If there are characters moving in the scene, you should first of all advice using Ctrl + F11 (pause) to avoid crashes.
 

Diavolo

Knight
M&BWB
Best answers
0
I would however rather just avoid characters moving when editing. (done by choosing edit settlement (cheat) when you enter the settlement)
 

Adorno

Bedroom Assassin
Duke
WBNWM&BVC
Best answers
0
That's also an option - in Custom Settlements. But then people will get in trouble if they try it in native, where there's no such option  :smile:
The tutorial (I haven't seen a similar one on AI mesh) might inspire people to edit scenes in general... 
 

Diavolo

Knight
M&BWB
Best answers
0
yes, this is the best forum to visit for everyone who wants to learn more about editing scenes.
 

Berpol

Grandmaster Knight
M&B
Best answers
0
Anyone has a tip how I should proceed with the following:
I removed the AI mesh from parts of the river bank (the steep parts) so the only reasons someone is in the river are
[list type=decimal]
[*]he's crossing the river where I want him to,
[*]he fell in from the bridge or
[*]he is following you.
[/list]
I noticed that 2 is no problem, they have no problem with being in a place without a mesh and got out again but I'm not sure about 3.
Should I cover the whole river with mesh or would it be better without the mesh at places I don't want them :?:

P.S. Currently there is no mesh under and near the bridge because I moved these parts onto the bridge :neutral:
 

Mortus

Veteran
Best answers
0
Berpol said:
Anyone has a tip how I should proceed with the following:
I removed the AI mesh from parts of the river bank (the steep parts) so the only reasons someone is in the river are
[list type=decimal]
[*]he's crossing the river where I want him to,
[*]he fell in from the bridge or
[*]he is following you.
[/list]
I noticed that 2 is no problem, they have no problem with being in a place without a mesh and got out again but I'm not sure about 3.
Should I cover the whole river with mesh or would it be better without the mesh at places I don't want them :?:

P.S. Currently there is no mesh under and near the bridge because I moved these parts onto the bridge :neutral:
I think that depends on the location of his target location after he stopped following you. If he'll walk back to the AI mesh while trying to reach it in the straight line, there must be no problems I believe. However, more testing needed here.
 

Berpol

Grandmaster Knight
M&B
Best answers
0
Mortus said:
I think that depends on the location of his target location after he stopped following you. If he'll walk back to the AI mesh while trying to reach it in the straight line, there must be no problems I believe. However, more testing needed here.
I guess I will try it this evening, both following the river and crossing it where I removed the mesh.

I made some tests:
When I ride along an area with no mesh my troops follow me without problems.
When I order them to me while I stand in an area without mesh, they ride following the mesh as far as they can and then come to me.
When I order them to me while I hide behind an area without mesh they ride along a way along the mesh.

It seems that my troops have no problems, they try to use the mesh as long as they can - just as intended.
 

NaglFaar

Baron
WBM&BNW
Best answers
0
Great tutorial. This will help alot of people to understand.

I was about to write one myself and then make a video tutorial to complement.
You just saved me a week.

Thanks again for the tutorial.