In order to have these bowls we've just create a roll across the surface the virtual surface which is
represented currently by the grid.
We need to make the grid a bit more solid or at least put something over the top of the grid that's
going to give us a collider.
The first thing to do to achieve all of this is first you want to grab your prefabs Safiyah and then
inspect to make sure that you attach a rigid body.
Now I've already done these.
We're also going to add a grand plan with shadows on it.
So for that.
Make yourself a transmat material using our trend's parent Shetterly Ruseva Shater that we've been using
all along.
Now I'm just want to play something and we'll just take a look at what's going on in the hierarchy with
respect to this trackable object because this trackable that is attached to the instant tracker is the
equivalent of the trackable that's attached to the image tracker.
So when this tracking is occurring it will be highlighted and when it's not occurring it's not holiday.
So we're just going to have a look at that in action.
So if I press play and I'm going to start tracking by looking at the ground and then slowly move this
camera up you can see over here in the hierarchy keep an eye on this.
So it's currently enabled.
So while the tracking is going on you can see it's still enabled but if you move too fast and it can't
track off on that point cloud data or any more notice that the trackable is now disabled so it's going
to have a very similar effect that the trackable on an image does as far as turning things on and off
automatically for us.
That means that we could make a plane and attach it to the trackball.
If it's at 0 0 0 with a identity rotation which is just your default rotation then it's going to be
sitting lost and flat with that great as we saw in the previous picture when we actually did put a plane
on that to see where it was situated.
Right so it will just stop playing.
What I'm going to do is I'm selecting my trackball and I'm going to right click create a 3D object plane
and attach that and make sure in the transform that it's all zeroed one scale.
The scale of course you can set that to as big as your particular table top is going to be that you
want to work on.
Now also you want to make it invisible but have shadows so we're going to grab hold of these transmat
and drag that on in the Sayne to apply this spline will automatically come with a mesh Collider which
will do all of that physics collision on a sphere that now has the rigid body.
Now we want to phase to move so we can apply a force to them at the top.
They're created and we can do that back in the controller.
So open up your script.
We're in sort of the update just off to your new object is created.
We're going to add on a force.
So we need to grab hold of its rigid body so new I get component rigid body add force.
Which direction do we want to add this force in well kind of forward from where the camera is so forward
from the camera is the main cameras forward transform so we can do that with camera Daut main dot transform
dart forward.
Now that's going to give you a normalized vector which only has a length of one which isn't a very strong
force so let's multiply this by 100.
Just to give it a bit of oomph so we can see it moving right.
That's all we're going to defend and save that.
And we're going to go back into unity press play and we'll start tracking actually now we'll stop the
tracking we'll point down the ground will stop the tracking and then we'll slowly come up.
So we got a bit of applying.
Now I've got to make sure that that trackable over heah hasn't disappeared.
Kazoos it disappears the tracking is not happening anymore and the plane will no longer exist and the
plane needs to exist.
If you want things to land on.
So let's now click in the sea.
Now you can see over here in the sane view that there's obviously a force going on on the spheres but
they're not going away and we think they should be going which is sort of forward along this ground
flying.
So what's happening.
Well when we click on the plane this fee is 0 0 0 which happens to be right in the center of the sphere
ends up sitting halfway through the plane which means that they're going to fall through the plane.
They're not actually above to begin with in order to bounce or fall onto the surface.
So that's easily fixed.
Stop playing.
Let's go back into the controller when we create the position of this phase which you remember is this
line here.
We should just lift it up a little bit.
So I'm going to add a new vector three in here and I will lift up that sphere by zero point one if I
remember is a scaled down quite small.
So zero point one is going to be enough and zero in the Zed direction and this will just lift it up.
Save that.
So let's press play stop my camera pointing at the ground against tracking lift it up to look at my
plan I can still see the trackable still highlighted.
And let me press clicked in in here.
Now you can see the bowls and they are rolling now.
You can also see where the end of that plane is that I've added which is like a bat here and they're
falling off down into the environment.
If you want them to roll all the way back up there then you're going to have to increase the size.
So let's just stop with that planning and are just going click my plan attach the trackable and let's
just make it 10 10 and 10 because we're not really interested in the full off at this stage.
What that will also make is in click further along on the plane up here and they won't just fly off
into space.
So let's press play.
And again we're pointing at the ground.
Let's track it and just lift it up so alone we make sure we don't lose our instant check checkable Now
you can see they are in the hierarchy.
I've lost it.
So it's become not there essentially if I now clicking here I'm getting absolutely nothing happening
because there's no tracking occurring.
So in order to fix that we need to just move it down a little bit find our point clear daughter again
and then just move that up slowly to there.
Now if I press I can click further in the distance and you also get those bulls everywhere.
Now you've probably realized by now as you've done more and more of these that the tracking capability
of your mobile device is a far more accurate than the one that's in the editor for unity.
But you want to do a lot of development as you can in unity because it's a really slow process to keep
building stuff out and building stuff that.
So even what we're doing here isn't aligned with the world properly.
But we still have all the components in there that will eventually come together and work on your mobile.
Now you can see those balls that cut right to the end in the distance now falling off of the edge.
Now as you would have seen when I demonstrated just before when you lose these trackable autumn in here
and it's not holiday any more.
The system is still telling us that it's tracking with the message down the border et cetera.
And so you might think it's still working when it's actually stopped it has stopped when that trackable
stops moving that checkable greed let's just press play and we can say that easily stopped checking
if we go really fast.
You can see that it hasn't even picked up anything.
There's a little bit there.
But when the grid stops moving then it's lost the cloud data so it can't keep tracking.
Now it's back to tracking at the moment because track trackable is highlighted.
But the issue with that is fair enough.
We can watch this change and become enabled and inactive in the hierarchy.
But on a mobile device you can't say that.
So it's not very good feedback for this to just stop working for us.
So we're going to add a few more Colback events into here which can then just improve the usability
of the system so back we go into controller.
Am I going to go down or up depending on where I've put these functions are the on scene recognized
and the on saying loss just underneath them going to put in a nother method that we will call from all
of these.
And what it's doing is it's enabling or disabling the grid that you can see based on what's passed through
which will then be in here.
So what I'm going to do is sort of the two methods above is just where where is tracking is being turned
on for this one which will be true.
So when is checking his turn on the grid will be content come enabled and then above this one will be
false.
Lot that now not only are we going to rely on these two callbacks we're going to put some more just
above here.
That will also help enhance things.
And these two that I've just added you can see on initializations Stoddard and on initializations stopped
so that we don't even have seen enabled when we haven't initialized yet.
And when we stop initialising it goes Folse again so we should find now that Assane and everything's
going to turn itself on and off based on where we're tracking and then when we're not tracking at all
we won't be able to see anything in which case we will know that it's not tracking is pretty obvious.
So let's save that and now we need to fade in to initialize zation So backing unity we're going to go
to our instant tracker and we're going to go to the trackable underneath it.
And you've got two events at the top.
You've got initializations started at initializations stopped so I can imagine that you know what we're
going to put into the controller.
Then we will go down into the control and find out initializations started.
And the same for this other one put the controller in and controller on initialization stopped.
So let's press play.
And how Look at how the grid now turns itself on and off.
So let's just start tracking.
Let's move it up so you can see it stopped tracking or lost the track and come back down and fanned
the saying that it recognized go back up.
It loses it comes back down.
Now can you see what's on the screen that isn't updating properly for us.
Yes this message bookstand the bottom at the moment we've lost the ability to track way in tracking
mode because we've already initialized it but we've lost the seen as such and therefore we need to change
a little message box here.
So what a good spot for a challenge for you.
Go ahead and see if you can get the right messages appearing for when you've lost the scene that we've
just created so that when the grid becomes disabled then you're going to get something down here that
says like Lost saying or something in a message that means something for the person who is using it
and pause the video.
When we come back I'll show you how to do it.
Such a simple thing to do.
I hope you figured it out.
So in your own scene recognize and you're on scene lost you just need to add text into your message
boxes so on saying recognize you can change your message box text to saying found and unsane lost.
You could put message box text to saying lost like that.
Now if you want to also do something with your initialization started and stopped.
You could put them in there as messages.
OK so save that.
Go back to unity and we're going to play again.
We'll start looking at the ground and let's press checking.
Now this just moves up a little bit and add some bulls in you can say now that the message down here
says saying fountain if I walk up and lose it it says Sayne lost and I can come back and when it finds
the cloud data to then it will still be there.
So what's at a funeral Sophies in here to try it again.
And come back now the issue here.
When we come back is that the SPEEs have gone but where have they gone to well when we lift up the camera
and the trackable is lost.
Remember this plane that they're rolling along it suddenly disappears.
And so it's not there for them to roll along anymore.
So that kind of causes a little bit of a problem because there's no more physics in the system.
So rather than having this plane on the track ball we could just have it exist the whole time with these
Svea is all we could take.
All of the spheres and make them children of the trackable.
Now what are the ups and downs of both of these methods.
Well if the plane becomes part of the entire scene it's going to exist the whole time the trackable
can go on and off.
But the speeds and the wind will continue to exist and will continue to be simulated in the system which
is a good thing right.
That's especially if you want to have something going on all the way around you.
And if you know looking at it you still want it coming towards you for example.
So that's one thing.
The other thing now if you do then look off of them.
Look way off the track it becomes inactive which means tracking is no longer working.
Then you really don't want to see those objects either.
So you want them to keep simulating so that when you can see them again they come back but not when
there's no tracking happening.
Otherwise they will appear to be rendered in the wrong place.
If you make all of the spheres children's of the trackable then the plane and the seas are only going
to simulate in the physics system while they are active and they won't be active when the trackable
is not showing.
So if you look away from SPIE is rolling away from you and lose them and then come back again then they
won't have moved.
The simulation will start from where it was forces to sort of things you can pay off there now if you
wanted to make this these children of the trackable It's Have a look at that.
We would go into the controller.
And that's very easily done inside Updyke.
So after where we've created it will go into a dot transform to a parent equals this.
No not this trackable which is trackable dot Trents form and they will now be children so let's say
it and have a look.
Go back to the Pressplay and we've got try we'll start tracking.
And as I click and add these bowls you can see them all appear in the hierarchy under trackable.
So if I create more.
And then slowly look up I should be able to see them rolling away from us and then they are now when
they disappear like that when we come back and find them.
You can see them at the top of the screen there just before I lose my tracker again is that they will
the simulation will still be running so if on here and they are all going to just create a whole heap
of them and then quickly look away and then we'll come back and find them.
Simulation resumes from where it was before.
So that is method number one.
Now method number two is to take a plane and to put it out here.
Now make sure when you do bring it out here that we check that it's 0 0 0.
Let's put the scaling up to 10 because it did actually change when you parent or child something will
remove them for that sort of relationship there.
Transform can change back into world coordinates if they've got a local coordinate system because they
are attached to something.
So always be sure of that.
So with the pipeline now outside let's go back into the cupboard and we will just command at this line
save it and press play and have a look at this behavior.
So did the ground stop tracking start adding these balls hooking up kind of already lost it.
But you did see that the bulls were still in the scene if you wish when the grid is removed say the
bulls are moving up.
Now they're not moving up because I'm moving the camera actually rolling out of the scene and we can
see it there.
So the grid is gone but the bulls are still simulating which is kind of what we want.
Which is nice in that situation but when you lose the grid they're now not fixed on that grid surface.
They're just floating off into pretty much no way.
So to do this we want to turn them off from rendering but still leave the game object alive and we're
going to come back in the next video and look at how that is done.