I think it's time that you had a little challenge for the instant tracker.
So in this challenge what I'd like you to do is integrate the dinosaur eating hamburgers tutorial that
we did in another section and put it into the instant tracking so that you don't need to use a Mac.
Now now notice in the saying that I'm currently playing it's pretty much the same dynamic.
You touch the screen it drops a hamburger and the dinosaur goes after it.
I've also turned off the grid so that it's not sort of spoiling the experience.
So pause a video now and give this a go.
When we come back I'll show you how I put it together.
OK so here's my project in unity.
How did you go.
There's a few little nuances and fiddly bits that you have to get right in order for this to all come
together.
It's not a matter of just grabbing the dinosaur from the previous one and dropping it into this scene
with the control for an instant tracking.
But what I have done is make use of the code for the controller.
Now you can say from my control that's in the hierarchy that instead of the speeches and the zombies
that are coming through in the previous examples I've got the Dawna's saw prefab coming in and the hamburger
prefab coming in because the donor prefab is coming in via the control of the controller will instantiate
that.
That means that the trackable object still hasn't got a dribble and doesn't have any child under it.
So that's not naked all the exact same callbacks that we had before.
So I didn't even touch these I've left them in there.
I've only edited the control code so I took the previous one with the zombies and the Bulls made a copy
of that project and took out the zombies you can see it.
I've still got the Svea prefabs sitting in there and then I got my Dawna's saw from the other project
and brought that in.
Now the script is going to change a little bit as well which was the touch move script.
I took the let's have a look at the dorsal prefab I took the touched a movie script off.
And I also took off the drive script.
They not named the animation stuff all exactly same.
Not touched whatsoever.
Now the touch to move script has morphed into what's called the eat script.
So it's very similar to that.
So the two scripts that we need to go through this new each one which is attached to the door and so
and the old control as far as all the other bits and paces the controller still has the grid render
that because we need it to a law and Assane before we start doing anything.
The plane from before is there with Al transmat Shater sitting on it.
We have our canvasses exactly the same canvas with the same buttons calling the same things messagebox
is still this law still doing what it did before.
And the kid chewed camera haven't touched that.
All the settings are still the same.
So let's have a look at the controller code first so go to click on the controller card.
Let's go up to the top.
The library is still the same.
The properties pretty much the same.
Ok so all of these things including the hamberger prefab are the same the only different thing is I've
added in this game object doyenne and it's going to grab hold of our dinosaur before we were instantiating
a whole bunch of zombies so that was spawning in this case we only want to spawn one dinosaur.
So when it comes time to turn that dinosaur off when we lose our tracking and we lose our scene then
it's much easier if we have hold of that dinosaur rather than do the search looking for an object with
a tag on it as we did with the zombies.
Now you can drop multiple hamburgers in this sense so that's fine for the hamburgers we can still search
through the game.
Same for the hamburgers.
And then pick them up and turn them off.
Now before we continue with this let's just go back into the scene for a moment.
If I click on my hamburger prefab I have had to over and inspect add a tag of hamburger to it so that
we can find it when we need to turn off the render.
All right.
So back to the control.
Moving down.
We've got our grid now trackable as before and we've got our sporting bhool as well which is going to
work slightly differently for the dam.
Now what we've got underneath here.
OK so this is still the same.
The wake is now taking out the trackable So it's not being used in this case which conman's I guess
we can get rid of this.
I'm not using it whatsoever so I'll just delete that.
All we're doing in a week is grabbing hold of our grid renderer and then turning it on the next two
methods for initializations started.
And initializations stopped there the same Bankole from the same place.
The next two for on Sayne recognized and on saying the last are the same.
OK so we're 16 and I will tour for recognized and true for tracking same fan message and for the last
as false false saying lost the set saying enabled is slight different.
It's still cold from like up here.
And all these other methods above.
But the first little bit that turned the grid on and off it's gone.
I don't want to control the grid being visible in here when the scene is lost and on I actually want
to do it elsewhere.
You'll say that in a moment.
Now for the hambo the render has to be turned off or on based on the same being found.
This is the same code that we had for the fees and the zombies.
But in this case we're looking for hamburgers.
Then we go through and turn the renderers on and off underneath that.
I'm doing the same with the Dawna's so but slightly differently.
I don't have to try and find the dinosaur using a tag because remember at the top there's a game object
called Dinon which is going to grab hold of our door and I once it has been instantiated so we can simply
grab all the renderers that are attached to the dinosaur.
We want the renderers we can't just get one render up because a mesh or a model of something might have
more than one mesh on it or more than one object as a child component which needs to have its renderer
turned off so that's why I'm getting all of bandura components in the children of the dinosaur to make
sure that every little bit of that model is not rendered or is rendered based on this here.
Now the state button pressed.
Let's just move down.
It's got the spawning of the very first dinosaur in it.
So the moment that you press that button to start your augmented reality is when you want your first
dinosaur We want the dinosaur added to the environment.
So if is not spoon and spoon is set to false initially then we run a spoon domino method.
Now this is pretty much the spoon zombies that we had previously.
You'll see that when we get down to the bottom after we have spawned one soul we then it is spawned
to true so that any more presses of that button are not going to create any more dinosaurs.
We just have the one on a saw because that's all that we named below.
That is the same code that we had previously for changing states.
Each time the button is pressed between tracking and initialization.
Now there's a little tweak in here that now turns the grid off when you're tracking.
So what you're saying is has been started your Donisthorpe is in there.
I'm adding hamburgs.
We don't want to see that little grid anymore.
We only use it right at the beginning to launch the sane up.
And so here we've got grid enabled is set to false.
Once we've gone into the set strip set state for tracking we turn the grid back on when we've turned
out tracking off and so down here we put grid enabled to try.
OK moving on.
The next one is on state changed now nothing has changed.
This is the same as it was before.
OK so it's just checking for tracking or not tracking.
Moving on we've got our method for our hi to justice slider.
That's exactly the same as it was now moving down to start the start is no longer doing any evokes invokes
so I should say.
All it's doing is just printing something into the message box.
Now the spawn zombie that we have before has now become spawn dawn.
It's going to spawn one dinosaur in a forward direction from the camera at a slightly random angle from
that and when it instantiates it this time it's going to grab hold of it with our property called Dawn
which allows us to turn the dinosaur on and off which makes that nice and convenient.
So that's now the spawn method in these moving down to the update which is our last one.
There's not a lot that is Changsha in here.
We've still got the functionality for clicking on the environment at least sending a write out creating
a ground plane to do the touch on and then getting the position of the touch and instantiating the hamburger
at that point.
Now the difference inside here to what we had with this is first of all we were increasing the height
slightly on the fees is that it was going to be above the ground.
And then after we created the sphere we were adding a force to push the sphere forward.
They start doing that with the hambo.
We just want it to stay put where we've clicked on the ground plan so that the d'Orsel can come over
and it.
So that does the hamburger that creates a hamburger for us and a Neith that we just move down again.
We've got our track est Monisha which will turn it to green or orange based on the current state of
your system and that is all the changes in the controller.
Now the other one is the old touch to move which is now called 8.
Let's have a look at what it looks like.
This is the same at the top.
I said the name has changed.
These objects properties I should say is still the same.
The accuracy of it in this case is zero point three spade in the rotational speed of course are still
the same.
We've got our food game object which hold on to the current hamburger that we're going after and the
goalpost which is the position of that hamburger.
We have the hamburgers prefab being passed through to instantiate it.
Now we were instantiating And inside this code we're no longer doing that.
So you don't need this let's get rid of that lawn.
We do need this game object though because the dinosaur needs to be able to find food in the environment
and then go towards it.
All right so moving down we have the start method which is getting our animators so that we can animate
it based on the state of the dinosaur inside of the update.
Now that's where things are slightly different.
Or I should say actually a lot different to what was in the previous touched him move.
If the dinosaurs food game object is no it means the daurna store is standing around with nothing to
do.
It's not currently heading towards food or eating food.
Now if this is the case the dinosaur should search the environment for some food.
So we do I find game objects with tag here to get the hamburger.
In previous dámaso hamburger aging one we had it so that you couldn't add another Hamburgh if there
was already a hamburger there.
This one allows you to add as many hamburgers as you like in the environment.
And then when it comes to finding a hamburger the dinosaur is going to do a search through the environment
and pick up all of the hamburgers and put it into these game objects right.
Then we do a little test if the game objects the right is greater than zero it's length.
Then there's obviously hamburgers in the environment.
We're going to grab the first hamburger that happens to be in that environment.
Use that hamburger as the goal position.
So if you've got a whole bunch of hamburgers that have been added to the game and varments you I'd like
five hamburgers then this code here is going to allow the dinosaur to move along and ate one and then
get to the next one and eat that next one take that next one and eat that.
So it will allow that food to exist the whole time until the hamburgers are Aten.
Notice we also when we instantiated the hamburger is in the control that we don't create any destroy
code on them so we're not destroying them after 40 seconds or anything.
They exist for the whole time.
We haven't got around to destroying them.
That's going to happen in the light of day where the animations in the movement is controlled.
So just here in this light update and let me just see if I can fit all of the code in.
So just under that it's not going to fit.
That's ok I will scroll down this look at direction rotation stuff that's all aside.
So this dinosaur still going to look at the goal position and slip towards and turn nicely as it's moving
along.
We then have our accuracy test to see if we're close enough to the hamburger.
Which means we will come in if we're not close enough.
We will keep moving forward with a running animation and the speed set to one if we are within the accuracy
righting of the hamburger.
Then when going to sit is running to fall so we stopped moving.
If the food is not equal to now the food is still there then we're going to sit the eating animation.
Now at the time we start eating well then going to destroy the food after four seconds.
So the aging animation is about four seconds which nicely times the hamburger should just disappear
from Al Sayne when he puts his head up.
So that works well.
Then underneath that we have if the food is no then we say it is aging too false.
Now this is going to occur when the food gets destroyed and we'll stop eating and go back into an idle
state until list somewhere else to move McKay.
And that's the end of that.
Each code.
So now back in unity the eight code goes on your Astle prefab and the controller code is in the same
place as before.
So that is the entire setup for this project.
Now when we run it let me run it in the editor for you.
I'll start the tracking by looking at the ground.
Now currently we don't have the dinosaur in the scene if I hit stop tracking the grid disappears and
the dinosaur is cloned.
He's also cloned somewhere in front of the camera.
Now he's great position is set to somewhere else on the grid.
But his goal position is set to zero zero zero because there's no food.
But the goal position is an empty vector or just a 0 0 0 1 so you could see him running into the thing
and running up to the camera.
Now if I can lift up my camera the only clue we've got at this point that we still have hold of the
scene is a little scene found messagebox in the meat go up a bit.
Now there's the dinosaurs big foot.
In this scene let me try and click over here.
OK so this is the dinosaur now moving not the greit look in the editor but we can see it's working.
So I can't get a really good depth of field in this position.
But it does work very nicely when you put it into your mobile let's go back up there see if we can gain
by getting his feet out there.
But here he is in the same car.
So this works brilliantly when you put it onto your mobile device.
So here it is running on my Android device the first thing you need to do is a line that grid with the
surface that you want the experience on and you can change the size of the grid as well as position
your camera and the orientation to get it right once you've got it where you want to click on your tracking
button.
And then you can start tapping the screen to drop hamburgers.
You can also quite nicely move the camera around and the tracking is just so good and smooth that it
does keep track of it even when you go to like zoom in on the little character.
And so it's a really really nice effect for having a bit of a play around with these instant tracking.
So I hope you enjoyed that challenge.
I certainly enjoyed making it and that you can see a lot of the possibilities with instant tracking.