hi and welcome back recently i've been asked a lot to do a tutorial about a ar indoor navigation video on my channel the link is in the description box so i decided to just do some kind of short tutorial i've not really prepared for this so this is just a quick shot don't wonder if i have a few mistakes in there i will just cut the videos so that you have the most information out of it and the working prototype at the end don't waste any more time and let's get started so first of all i created an empty unity project with the 3d template and we'll try to do the basic settings for getting started with ar foundation and ar core so at the player settings at the android settings we're just removing the vulkan api at first then dynamic switch dynamic batching on everything else this looks good make sure to use at least android 7 for the minimum api level the scripting backend to il to cpp and api.net framework target actuator architecture to rm 64. and i think all the other settings are fine for easier handling we'll just use the old input manager feel free to change the to the new one and that's basically it so we can switch to the android platform now go to build settings select android switch platform and wait for it to finish at the sample scene here close build settings go back to the player settings install the x xr plugin management and and beneath android just check ar core to have all the xr ar core packages imported next step is to open the package manager and install ar foundation from the unity registry here we go as we see the ar core xr plugin is already installed er foundation will be installed now if you look for samples they are available at the unity github repository will we won't need them here so delete the main camera right click xr ar session origin for our ar camera and the ar session added the same way and we'll see here here session input manager if we need something else like the ar income manager for ar anchors we can add it here but i'll just leave it out now to show that it works basically without everything else and that's everything we have to do for ar foundation to get it working next is to create a new folder call it textures we'll add a mini map texture here i just created a mini map texture in paint from my current hotel room it's not very accurate from the measurements but it will do i guess just drag it in here and change it from default to sprite to the end ui texture type to make it usable as a mini map preview here we go here looks good and right click in the hierarchy 3d object cube this will be our floor cube yes just make it a floor floor cube and reset it from the position and make it in the the scale in the y-axis x 0.01 6 and zx is 3 this will more or less be the measurements of my hotel room at the moment this looks good and now we're going to add the minimap to our floor to have some kind of overview create a new folder call it materials and within the materials folder we add a new material floor mat oh forget the mat just call it floor and switch the shader to unlit texture and select the casual map the minimap and we'll see when we add our material to the floor cube okay we have to turn it around 180 degrees that this already looks like a mini-map to us just leave it for now create a new empty game object call it environment reset it and make the floor cube with child and again add a cube to the environment as a child this cube will basically be our walls just add it to isometric view now just change it to isometric view now for easier placement and we'll place the cube here scale it down the thickness to about 0.06 must not be exactly but making sure that everything at the wall cube aligns accordingly to our minimap or to a floor plan or however you call it duplicate it move it to the other side duplicate it again and just rebuild the geometry of this room here we go just a few little adjustments you can feel free to create your own map of your own room or floor however and align the cubes accordingly here we go just change the set scaling to 0.06 for the horizontal walls scale it up into the x dimension here we go move it to the top nice duplicate it let's move it down so we basically have a room finished no the interior walls are missing okay duplicate it scale it place one on the interior on the inner walls and then finish up the door to the bathroom i'll just try to make it as close to the floor plan as possible that looks good half of the walls are throughout the floor so we'll just have to move them up a little bit and make them bigger around two meters high they're actually higher but that doesn't really matter now move it up one and so here's basically a very simple model of our room create a new material here for our walls as we want the walls to only occlude and not be visible right click create material call it wall and now that's very cool trick go to shader vr spatial mapping and occlusion so everything that has this material will be invisible but will still occlude other things and that's exactly what we want we want some kind of invisible walls in our ar application no need to cast shadows no need to receive shadows um well well let's do it like this it's basically fine so let's make our environment static because we want to switch to a navigation mesh and we basically want to have a navigation mesh on our floor cube which originates in the lower in the upper left corner and gets to the bathroom so moving the geometry so that the starting point zero zero zero in world aligns with with our starting point on the geometry just aligning it a little bit more and i would say our target should then be in the bathroom well to do some navigation part of this the next part will be to add our navigation mesh move to window ai and navigation so the navigation tab will pop up with a few tabs agents with all the settings areas bake object and in the bake tab we'll click on bake and we'll see okay our navigation mesh is pretty small because our agent has a radius of 0.5 meters and it will not fit through the hallway and the bathroom so the easiest way to solve this is to reduce the radius to 0.0.2 click on bake and this already looks pretty good we have a navigation mesh and that's navigator ball save it right click in the hierarchy 3d object sphere no i think we dropped a sphere i would like to have a cube here right click with the object cube and this will be our target cube 0.2 0.2 0-2 in the scale to make it a little bit smaller and reset the position and then move it to our target space i'd say the bathroom with the toilet will be a good opportunity move it one meter up so it's above the floor and create a new material for this we call it the target and we'll just what color do we want to choose i would say green would be sufficiently make it a full green here we go you can also use some kind of unlit color i just leave the standard shader here as it doesn't really matter and it helps us to see some kind of helps us to see the cube better cool let's rename it to target cube you can make it static too and what would be the next step well we can navigate we have a target but we still need some kind of indicator so we create a new game object call it indicator and beneath this indicator we create a new 3d object this time we'll go with a sphere call it indicator sphere and create a new material here we go indicator and let's make the indicator blue standard shader is also sufficient here make it full blue here we go add it here and change the skill to zero dot 0.0.2 move it one meter up i guess it's too small make it 0.3 and move it to our origin indicator is not at the origin zero zero zero so the indicator will always be where our application will start and we want our indicator to follow our target so we'll just use a position constraint instead of some kind of script added here click is active and under constraint settings uncheck the y part this is basically very important because although this property's name is freeze position axis it just tells us that the position constraint can change each axis which is checked so in this case the position constraint can change our x-axis and z-axis but it cannot change the y-axis that's what we want we want to move the set in the x direction in case of our minimap but not in the y direction and now we add some source iso source is the ar camera as it's moving through our room and that's basically the setup for a position constraint and nevertheless we need something to visualize it so that we had a line renderer here and we see that the material is pink so we just create one add a new material call it line make it unlit and color and adding a color i'll just add my favorite blue color for lines is 8080 and c8 some kind of bluish color add it to the line renderer of an indicator on the materials line here we go and it's basically very wide so we reduce the width to 0.1 just fiddling around a little bit to make it as accurate as possible and there is still a preview so we'll change the second position to zero zero zero that it's not so it's not visible nice this looks good in the lighting settings we can cast shadows off receive shadows off it's not necessary for us here and basically have a line here this line will indicate our way from our current position to our target and will be tracked via the ar camera so nevertheless we need something that displays our minimap so we add a camera as childhood of the indicator call it top down camera and in this camera we'll just rotate it to look downwards 90 degrees in the x direction make the projection autographic and move it up about i don't know let's say five meters doesn't matter because it's autographic and make the size let's play around a little bit yes i'd say around one would be pretty nice here we go and this camera will render its image here in the preview and we want it to render it in a designated target texture so we can display it within our application so in the assets folder create a new folder call it render texture and within this folder add a new render texture create and render under render texture call it minimap all the default settings are basically fine you can always change it if you want to but we'll just go with it and add the reindeer texture to the target texture and as we see the camera is already rendered here so we have nearly all of our parts finished the environment will just add a few layers to configure our environment i'll start with layer 8 and make a floor layer on layer 9 it will be a wall layer and so on just feel free to add layers as much as you want for configuring the visibility and in our air camera we'll just uncheck the floor and the wall i'm not quite sure if this will work like i'm intending to but we'll see i'll make sure to watch the video until the end to um check for possible mistakes our top-down camera should render everything no i guess we can omit the ui here just made it we'll see we'll change it later on okay nice um [Music] the next part of the minimap will be our ui just go to i add a raw image i'll rename the canvas to minimap canvas and in the raw image in the texture part add our render texture and if we switch to the game view i'm just changing the aspect to portrait to get a better understanding of how it will look on our smartphone we already see the pre-rendered picture but the size is not very good so we can either change the scale factor i would not recommend that because it will change the scale of all child objects just leave it at one or in the raw image change the scale here but changing the scale is always let's say it's not always the best solution basically changing the width and the height is way better leave it at 500 times 500 well that looks pretty neat i'm changing the anchor to centered and 0 and make the y position i don't know 400 oh it's a little bit too high 350 maybe 300 yeah that looks nice i guess we'll just stay with that and yeah that's basically a mini map that should work like intended array cast targeted last is not necessary so let's add a new folder in the assets folder call it scripts and we'll add the one very short script here instead of typing everything we'll just call it set navigation target i'll just provided a full code and we'll talk about it i think that's way better than type all the variables and everything by hand i'll just copy it in here here we go just a little just adding the missing usings for navigation unity dot do a little bit of formatting that it looks neat here we go and make it a little bit bigger what do we have here so first of all field for the top down camera i filled for the navigation target then the navigation mesh path that will be calculated our line renderer could also be a serialized field it doesn't matter and the line toggle to start and stop that calculation create a new path get the line renderer component and every time we touch the screen the line toggle will be toggled and if it's true the nav mesh will calculate our part from our current position to a nav target and configure the line renderer accordingly and just enable it initially well this is not the best script but i think everyone can understand was it what it's doing wait for unity to compile everything and i guess that's it adding the script to our indicator down here set navigation target the top down camera adding the child here and the nav target object is our target cube here we go and let's think about it i have forgotten anything well i guess i just try and cut the video and after trying i found out that the display is not right of our floor and wall because i forgot to set the layers so add the layer for floor cube to floor and the wall cubes to wall and then let's see we have to adjust the geometry a little bit move the cube a little bit right here right over here so my estimated map is not working that good just doing a little bit of movement to get the correct values right over here and maybe we should move the walls to [Music] let's see i'll try it and cut the video here yes okay after trying everything we have to move the walls too just make this one smaller here we go and move it over here and make the bathroom a little bit bigger i thought it is smaller it is that's not the case after all and move the cube to zero zero zero to the same level as the starting point just slight adjustments here feel free to do them as you want and refresh your navigation mesh click on bake again well this looks pretty good maybe the cube should be a little bit more in the center i don't know i'll try it and come back to you in a moment okay here we are again and let's see our ar camera we just missed to display the walls as i thought something will go wrong and okay serious property i guess that does not count to anything that we've done here just checking the calling mask again this looks pretty good we should move the environment down about one meter because our starting point will be about one meter above the ground minus no minus one this is a very crucial moment because we're changing the environment here so actually you can re-center your environment for instance by scanning a qr code or something else i'll just do it manually here so everything will be easy when you look for something like qr code scanning i can totally recommend the zbrushing qr code scanner it's very easy to integrate so but that's another story just google it and i'm pretty sure you will find something that will work so this now looks good i guess that's everything just checking if this will work out okay file build settings and again build and run on my good old google pixel 2 i have a newer device to test but i just wanted to show that it will also work on all the devices and here we go starting the application the minimap already is working pretty nice the feature detection of air core is also pretty good tapping the screen after getting up sorry for the mess and i'm moving and you see the mini map on the ground moving too and here we are in the bathroom where our cube is located i'll just go backwards trying not to stumble upon something and in our in the bedroom i'm trying to move around a little bit to show that the tracking actually is pretty good here we are nice still where we left it turning around and that's it so thank you for watching um please like and subscribe and leave a comment if you want to see more of this short tutorial videos so thank you and see you soon bye