In this lecture we're going to create a 3-D Mocca but also have it as an object that can include virtual
things so that if the virtual character goes behind the 3-D object then you won't be able to see it
very much in the same way as we've done before where we've had zombies under the ground and we've had
ghosts walking through walls.
It's the same thing.
But this time it's a 3D object that is providing our point of reference.
Right.
So to do this and to follow along I've got to tell you know file and some images that you can print
out to show to your camera or you can of course use your own 3-D object.
So the WTO and the files the image files are called Brown hot.
So grab those and make sure you bring in your w t file and put it in the streaming assets.
We get chewed Walda.
So mine is just there now backing assets what I've got.
I've brought in the occlusions Shamita and I've made an occlusion material with it.
You can also see a transparent material and transparent shadow although I'm not actually using those
in here.
I've also brought in something to go around this pot that I've got the pots quite spherical and I'm
just going to fly a little character around the pot so the character of God is this little fellow here
and I've bought him from the asset store quite a wallet guy but he's quite cute.
Now if you do a search for dragon in the asset store you'll find quite a few free dragons that you can
download with animations animations on these all the characters a little tricky to set up.
If you don't know what you're doing I'm going to just quickly give you an overview of how they're set
up on this little guy cause they most likely to be very similar.
On the other dragon models and I did find some other dragon models that use the old animation system
when you get this guy to work.
Let me just press play and we'll be able to see him.
OK so there he is this is what he's doing.
He is flying continuously and we want him to fly around this particular part.
Now he's enemy needs to be looped.
When you get them sometimes they're not looped and sometimes not sit to flaw ADA.
So let me select my dragon.
When you select your character over in the inspector you'll find on my find an animation component added
to it and then it has a section for animations.
Now this guy was set to walk I think when I go I mean you can just click on that and find the correct
animation you want.
So in this case it's fly forward.
That will set it to automatically play.
Because this tick box you play automatically will be ticked.
But if you want the animation to loop then just click on fly forward and down in the project you will
find the animation inside of the packages select on that animation file go over to the inspector hit
it it and then with the animation tab selected these fly forward at that select.
This ammonia currently worth more.
Now if we go down and go down you'll see ad loop frame checkbooks.
Take that and then the wrap mode you want to be set to loop.
So it might be on something like default or once and therefore it might play once but no I ran and ran.
If you want to constantly loop than you would do that then hit the Apply button and that will give you
a character that is just constantly running the same animation over and over again if you're not following
along with it and you don't want to do the animation.
The next fun is it doesn't need the animation you can still just use a model of basically anything and
will have it revolve around a spherical object.
OK so let's get rid of that dragon out of there.
We're going to add into a hierarchy an object Cheka.
So have a look for object Cheka and drag and drop one of those into your sayne.
Select the Cheka and you want to change the target collection from the firetruck to brown pot.
So just find that WTO fall and put it in there.
So that's now going to find that Bram pot whether the actual brown part that I've got or bay the images
that you can print out.
So now we want the dragon to appear when the trackball becomes active.
Easy enough.
So back into the assets we will get the Dragon or whatever you're using over and drop it on to the drawable
of the trackable.
Now the other thing that we want is a sphere because this part is pretty much C-shaped.
Ideally you would have a three day model of the actual plot so that you've got like a perfect occlude
for it in this case we don't.
However if you have a look at the sample file it comes with wicked chewed for the firetruck.
You will find that there is an actual fire truck model there that is used as the occlude for the fire
truck application.
And so the actual real fire truck and the model are exactly the same.
Therefore they fit quite neatly together.
And when one is occluded then it allows you to put objects and augmented content behind the real world
object.
Or at least fake that sort of thing.
All right so for a trackable we can add another drawable but we can add to it.
I SPia as a child so go through the object SPia.
And that's going to give you a sphere about the size 1 1 1.
You might have to modify this and you might also have to modify the actual position of it when it comes
up on the screen.
But for now we'll just leave it where it is.
Now I'm not going to put the excluder material on it right now cause you want to get it positioned just
right.
OK.
So with that done the other thing you might want to think about is where is this dragon going to appear
when it lands on your trackable So if we grab the dragon again and actually make it a child of the track
we'll just to have a look.
Where is my dragon has been moved along its y and its x axis which is why it's a way from 0 0 0 it's
also up a little bit and it's scaled by 5 and you can see that over in my Inspectah you want to move
your dragon or model away from 0 0 0 because we're going to have it fly around but it can't fly around
if it's sitting right in the middle of that to sort of spin on the spot.
So think about where you want your object to start.
And it's fine if you start it off where I've got mine.
So that's actually set in the prefab.
If it's not for you just here to play and make sure that you saw that back OK let's remove that now
we can try it out.
So press play and amusing my web cam here to start with to get some basic alignments dismiss it.
So you can currently see that the Safiya is of size when my mum doesn't quite fit over the pot to occlude
it.
So from here while you're still playing if we click on the Safiyah we can resize it.
So let's just make it point five point five and one point five.
Now you can say that it's much better and it needs to kind of sit neatly into it.
If you can.
Otherwise it won't completely occlude in the right spot so we could actually move it across this way
which is going to be moving it in the Zed direction just a little bit.
So just move it there.
It's not perfect.
As I said before we could even make it more egg shaped to try and fit out these bulges but at least
you gave you some idea of how it's meant to work as far as the occlusion goes.
Now with those settings on the Svea I'm just going to drop down the menu up the top in the transform.
Show you what that looks like and go copy component to get hold of these values and then stop playing
click on the sphere again and then do a paste component.
And let's just bring that back action OK so let's run it again and have a look at where else the seats
are right.
So as Sophia is now much better coverage of the pot and you can see the little dragon he's still far
enough away.
So let's stop playing with that Safiya.
We can add the occlusion material.
If we're happy with it and if I press play again you won't be able to see it.
But if the dragon goes behind the pause then it will be occluded while you're playing.
If you select your Driton which should be attached to the brown pot Mocca or marker I guess it's on
the trackable the grab your dragon and we just move him behind the pot.
You can see how he is occluded so or that if he was to fly behind he will disappear.
Now you can also see up here where that Sophia doesn't fit into the top of this model.
OK so you could like add a cube and other things to just flesh it out if you wanted to.
Nephritis bring him down a little bit and bring him and you'll see that you've also got that Sofia overlapping
there.
So this is the background this is the video feed sitting over the top of that Svea and not including
him if he goes down a little bit more and comes out you'll see the spots where he goes over the top
of the video Faid which is what he's going to naturally do.
And this the occludes that's stopping that from happening.
So you know this is not too bad.
I mean for Sophia and an object you're trying to occlude to be the same exact same perfect shape.
And you know it's not that right.
So we've got that.
Now what we're going to do is make the Dragon Fly to do that.
Are you going to write a little bit of code so let's go create C-Sharp and we'll call it fly.
We want to open that up and we're going to use a little bit of mathematics to make him fly in a circle
around the pot.
Now the part as far as the dragon is concerned is at 0 0 0 which makes these calculations quite easy.
First of all we need two equals zero.
This is time having traveled around the pot and float radius cools 1.5 F and this will be the distance
from the center of the pot from the origin.
We're going to use parametric equations to calculate the circle and move the dragon around it.
So these are quite easy because it's just a combination of saw and and cosen in the update is where
we'll do this.
So applying something like this way we're only modifying the X in the Zed.
OK we want it to be at the same height the same way around.
So it's the cosign of T multiplied by the radius and the sign of a multiplied by the radius added to
X and Zed then we calculate the new position being a vector three value same y as we have before using
the new calculated x and z and then we use this position to update the dragon's position.
Now after that to keep moving round in a circle we need to update the value of t.
This value you're adding to t will affect the spade.
So if you put one in here the dragon zipping around really really fast.
Or if you put 0.00 your want he'll be going very very slowly so it's up to you how fast you want it
to go and the kind of luck that you're after.
So with that save it let's go back into uni and we're going to find dragon prefab which is here and
drag and drop our fly script onto it.
All right let's have a look at the behavior that we get from that skritch.
So here he is we can see over in the scene actually you can see the occluded Sophia in the scene just
when he goes behind you can like that.
Now there's a slight problem with the way he's flying.
He's probably a little bit too fast but he's not facing in the direction he's flying.
We probably like him to face forward all the time.
Not Garonne income backwoods.
So let's stop playing and just make those amendments to our code go back in here now to do that.
We need to calculate where he'll be in the next timeframe.
So in the next time frame if we just grab this code just paid it for X next and zid next he's going
to be at time plus equals zero point one if.
But we're just going to slow it down a little bit so just put a zero in there.
This is going to update the value of t and also use it.
It also means we have to get rid of that other update a little further down.
OK so let's do that and we'll get rid of this.
Now we need to calculate or set up a new vector that will be the next position that he's going to be
in.
So instead of new possible cool this next pause and fit x it will be X next.
And said it will be Zed next.
Then after we set that position we can use a look at.
So this dot transform don't look at the next pause like that.
Now I know in the past I've used a slip because a slip is a smooth rotation rather than an instant look
at.
But you have to think that this little guy is going around quite fast and we're calculating only a very
small step around the circle each time.
So therefore I look at it will look smooth.
Anyway in this instance sorry let's just say that let's go back into unity and we will press play and
have a look at the final result.
So he'll now be flying around
and you can see there.
Now he's probably not in the best position in this camera review to be very much occluded like you can
see.
He's only getting occluded by his fate.
So let's stop playing.
Click on the drag and the dragon is actually at the Y minus zero point five.
So let's maybe make that 0 or point eight and just try it again.
That will lower him a bit.
Hopefully we'll get to see the occlusion effect from that noise still a bit too high.
And you guys getting included by that.
OK so let's change that now to maybe down to 1.5 play
and now he should get behind this book and then you guys see so he gets included as he goes behind.
And then he comes at the other side.
Now if he was going quite fast you and there was a lot of stuff going on the sane the fact that this
isn't perfect preclusion you might actually get away with.
But this shows you how the job is done anyway.
And for this example it's close enough.
Now I do have another tutorial using the same port that builds a fishtank system and an aquarium over
the top of the pot.
If you'd like to have a look at that or learn how to do that.
That whole tutorial is in youtube and it has a flocking algorithm that comes with it.
So now you can build this app to your phone.
You can program in your own object and take it from there.
And in fact you don't have to use a Safiya cube would be quite an easy thing to do and there's a lot
of sort of Kubic objects in the world or rectangular prisms that would allow you to make a much better
match with a unity primitive used as the Cluedo.