In these next few videos we're going to create a little project using multiple markers and recognizing
them not just as individual markers but in a sequence in order to create a little spelling game so you
can say here that with spelling the word ka when the correct letters are found a little tick will come
up over it.
And when the whole word is found then we get an animated character up here to begin you going to need
some assets that are attached to this lecture as resources.
And so in May you'll find a zipped fall with alphabet characters in them that look like these is not
the full alphabet.
It's just a short set that we'll be using.
There's also going to be two FBI x falls across and a tick so bring those into your project as well
as the chewed unity package so that we can set that up.
You'll see that I've already added in the wicket shoot camera into my hierarchy and I have an image
tracker which brings with it a trackball.
So that's all I've done so far.
So bring those alphabet characters in.
And what we will do first is create lw a safe.
So I will do that in the editorial three window WTC etc..
Now I'm going to create a new one.
When you go to create a new one.
It will need an initial image so let me just select this first image you'll see.
In this case that I get it put in the streaming assets it needs to be in side of the chewed folder to
move this.
You can just do that down in your project and just go to streaming assets and then drag and drop it
in two.
We could shoot.
That's just one of those little funny things I found with it.
Now you might want to rename it because we don't want a cold C. We're going to call this alpha a bit.
Now if you're not working with the editor itself this is added a he or it's not working for you.
Do feel free to go to the studio on the Web site and add all of these to make your WTC file.
So all just quickly now add the rest of those images.
Now with these you can see that they are all three star markers.
If you go ahead and create your own a little bit later on.
Don't forget to test that you do have like a high number of styles on them now the single fonts and
I found this through experimentation and I did a lot of experimentation as well is that it's really
hard to get really good markers with three styles just by using a font.
And that's why I found this sort of paint splashed decoration to put on it just to give me some more
sort of feature points in the image but also not to negate the fact that you really want to be able
to see the alphabetical character on the marker itself.
Right so now we have a WTC fall called Alphabet and I just noticed I haven't put my eye in there which
is going to be critical for the words will be testing with so that he can hit a ploy.
Check it out right.
Ready to continue now in the hierarchy.
Have a look at my image checker.
It has the Target collection set to the wicked chewed alphabet.
WTC file.
And if we have a look at the checkable sitting underneath there you'll see all of the letters now showing
up in NE.
You want to make sure that they are all selected.
We're not going to have a trackable for every single letter in this case.
We're going to do it just a little bit differently now.
The image Cheka itself needs you to set the concurrent targets to however many leches you think you're
going to need in order to identify a particular word.
So we're working with like three letter words for this I'm going to set that to three.
Now we'll be able to pick up three of these characters here that are in our trackable so we can test
this out.
Now it's not going to be drawing anything on these markers but they are going to show up in the hierarchy
and in fact just to make sure that we have seen them all let's just drag out take object and just make
that the drawable for whatever thing is fans or when you have multiple trackings all under the one trackable
item and multiple ones get found.
Each one of them gets an instantiated version of whatever you put into the drawer.
OK so we're going to run this and I'm going to at the same time try and juggle two things at once with
my hand to come back and pause the running of this let's see if we can grab hold of these.
Like I said there's my three ticks that have come up and if I just move back safely without losing that.
OK so they still being identified.
I'm going to pause the playing because I want to show you what has just happened in the hierarchy.
Have a look in here.
When ever we could shoot identifies one of the target images it creates a new game object onda trackable
So it's a child.
There is one for the AI character one for the C character and one for the character so it's found all
of the correct characters.
It doesn't have them in the order we want them.
I'm aware about that a little bit later.
Now each one of these if we have a look what's actually a child of it you'll see that the ticks that
were instantiated attached to those nets was making those ticks Appia down in this all the very very
little.
OK so the name also which is important of H item H.
Image that has been created here is named after the trackable image.
So I for example in trackballs was called I in the targets and C was called SE and was called.
So this was like I don't jibe pig and say that J pig.
And that's how they going to be named.
And in this case the underscore one that you see at the end mean is that the first time that is found
an eye.
And when you lose the eye and come back and find it again you'll get an eye on the school too as having
been detected.
But what we're really interested in.
They leches at the beginning of what these game objects are code because these are the letters we want
to match in the word that we are trying to spell.
But currently we're not doing anything like that we're just making a ticket over a marker that is identified.
OK so stop playing that.
And while I'm thinking about it just click on the take model that you would have brought in go over
to the inspector click on model and you probably want to scale it up because it is quite small.
I'll try 5 for that.
So change of scale affected a 5.
Go down to where there's an Apply button and add that.
Now you might want to do that for the cross as well even though we're not using it.
We will come back and use it later on.
So what are we doing 5 here and we'll apply it.
And while I'm here I will.
So just quickly test it to make sure that that's the right size.
And of course you can modify it to be a different size if you want.
Like I said that's pretty good.
It's found those markets now it will also fall on the day and anything else that we decide to put in
he will find up to three of them at a time.
So it's not going to fund the day until it loses something else.
OK so that's pretty good.
I can I'm going to run this again to now show you how we're going to figure out if we've found a word
spelt correctly because I have to be spelt from left to right.
You don't just want to throw the letters in there in any order and have them say that the word is correct.
So let me just again grab those McLemore back pause it and once again we're going to go up the hierarchy
and have a little bit of a look at these three items that are underneath the trackable because it really
is all about these markers.
Before I even show you how I'm going to do this just take a moment pause a video and have a think about
OK we've got each of these things that have shown up.
How would we then write an algorithm to say that they're in the right order.
Well let's have a look at the position of H-1.
So the first one I see is at 0 0 0.
The next one see is at one point something basically 0 and point 0 9 and the AH is in negative one point
zero or something negative 0.04 which is almost pretty much zero.
And Zed's almost zero or two.
So it's point zero or two six six seven.
In this case.
So what's the relationship between these that we could use to sort them well if you had a little look
through the eyes while the video was paused you'll have noticed that I which was the first one that
was found is at a position of zero in the XX.
Now remember the x coordinate of something is going across the screen horizontally and the word is written
horizontally.
So as these x coordinate is actually key in this that will tell us whether these letters or where these
letters are with respect to a left to right direction.
So if we consider that is 0 or c is 1 and ah is negative 1.
So on the left of I see is that would be 1.
So in this case l x axis is actually running in a positive direction this way.
OK so the AH is at minus 1.
So it's on the other side of the eye.
So we know from this that if we can sort out Letta's here based on their x position that they appear
to then we can say yes they're in the wrong order of the word ka if.
Cause what you're trying to match or they're not.
And not only that but you can tell whether you have the right letter or not in the right position for
the word.
So we obviously have to sort these and the best time to sort them is when they are recognized.
So we're going to create ourselves a little script that's going to pick up on that target image recognized
that we've looked up before in the hierarchy Let's create an empty game object and we'll call this spelling
control for that will create its own C-Sharp script.
So create C-Sharp let's call it spelling control law.
Then we will open it up and edit it.
First things first let's just set all the libraries that we'll be using through out this of course we
need the wicked chewed the collections and the unity engine.
Notice I'm also throwing in the link library here as well.
We're going to use that for sorting because it just makes life so much easier.
Now we want to find all of the children that are attached to that trackable object.
So I'm going to pass through that trackable object into here so that we can access all of the children
public game object trackable now we don't need a start and an update.
But we do need an on image recognized at this point save your script go back into unity whale drag and
drop it onto our spelling control law then select your spelling control.
Grab your trackable object and put it into the public exposed trackable for spelling.
So now spelling will have complete access to track well before we even start applying this trackable
but it has no children.
They only appear every time a marker is recognized.
Right so now let's go ahead and print out a list of all of those children as it finds them.
So back in the code we will go into Hero and add this bit of code what it's doing is grabbing all of
the children that are attached to that trackable so get components in children.
We're going to look for all of the transforms that exist as children put them into this array called
old transforms.
They move around this the right grabbing each one in turn and then we're just doing a D lug to print
out the name of the object a space and then followed by its exposition just to be sure what we've.
Gosh what we actually want in this array up here.
OK.
So save that.
Let's switch back to unity and before we do anything you need to go to your trackable and make sure
that you add an own image recognized into there and the inspector drag and drop your spelling control
onto there and then find that function that we just wrote under the spelling control which is your own
image recognized and put that in.
They said that it will run.
All right so this is going to print stuff at the console which you want to say I've got my console up
front here.
And let's press play.
Now it won't matter if I find the matches and then just lose them because it will print stuff out constantly
as it's found.
So let's just find them
OK and I'm going to stop playing now because I've got a record in my console.
Let's have a look at what we've got.
So there's a few things that are coming up.
The trackable itself.
Now this is going to print out every time you recognize something.
And the first thing that gets printed out is trackable 0.
What the last time it went through this sequence which is down the bottom so we got trackable zero trackable
zero or is the trackable itself.
So it comes up in that array.
Then we end up with a school one which is out Makana and its position is negative 1.1 for three three
whatever.
So that's good.
Then we get a tick.
So the client take the instantiated take that AP is also go to position and it's also in that array.
So that's not ideal because we don't want that that's not part of the wood.
Then we have a c and the C is at an x value of zero and then it has a tick as well.
Now and this said he must have been after it lost the eye.
So we can find one sit where there was a night there's an eye out there.
We have the eye at 0.
So he the first one here trackable 0 0 0 and it's tic we go to see at zero point six which is fine.
It's tic and then we have an Ah at zero and it's two.
Now this is an issue isn't it that the I and the aread exactly the same position when they're not.
We know they notshe but at the time we printing this out it's still registering it at zero or so.
What is actually happening here which is a little bit of a problem for us is at the time that we detect
the AH.
Which in this case was the last one that was detected.
It's detected but its actual position hasn't been calculated.
So that's quite annoying for us so we can't use that in this case.
But I do have a little trick to overcome that.
So let's go back into our code now instead of doing all of this inside of our own image you recognize
which we know does not Updyke the position of the last thing that was recognized when this is actually
run.
We're going to do something a little bit sneaky and create an extra Mithu Dan. he'll it's cool chick
spelling and I'm going to take all of that control X and put it down in here.
All right so now it's somewhere else.
When do we want this to actually run.
I'm just going to invoke Kurt and I need to make sure that when it seems that we've had at least a frame
in unity guy boss that the the actual game loop has run.
Now that means just giving it a little bit of a delay.
So I'm going to put zero point one if Sikkens in here which isn't going to affect the experience of
using the app whatsoever but it will give us enough of a delay in the program for our new positions
to come up.
So with that done let's save that and go back and try it again now because a time in his video is running
out I have already run this and just paused it when I found those three markers.
If we have a looking Konsole we'll now say that the markers at zero.
The same marker is at almost 1 and the marker is at minus 1 which is exactly where we want them.
We still have the problem when that old transforms arise picking up the trackable object itself and
all of the children that are underneath that lot the Teac and all the ticks that are sitting on the
other markers as well.
So we'll come back in the next video and actually clean up that right so that we're only left with the
letters and then we can check the actual spelling is correct or not.