In this Lakesha I'm going to show you how to make the objects look like they've come through or from
behind a real world object and you can see in this example that these zombie models appear to be coming
out of the floor.
Now in order to do that we need to somehow mask off where the flaw is relative to the Mokka itself which
is underneath that gravestone you can't see at the moment and then make that occlude the models when
they're underneath it.
Now to follow along with this project you're going to need unity three days Sayne you're also going
to need the zombie model with the animations and it's called Zombie unity package which is attached
to this lecture.
When you drag and drop that into your assets for you'll get Stevie who is zombie appear in your assets
that will also come with a fall that has all the models and animations for it.
In addition you'll need your own Mokka as well and that has to go into the streaming assets.
We could choose which means of course that you need to bring the original with a chewed plugin package
in and you can say I've got the modern art one that you were say in the previous example just.
So this is going to be my Mokka in this instance.
So let's begin.
We need our we could choose camera drag and drop that into the same.
We need an image tracker.
We're going to set our image trackers Target collection to be the modern art.
In this case and then on the image Checker's trackable we'll put the dribble object of Stavely like
that.
So in essence set up let's not forget to get rid of that initial main camera there.
So let's play this and have a look at what we get.
So let's move on Mocca to where the camera can see it.
OK.
Now say that the model is playing the animations and it appears to be climbing.
But it is still completely visible.
Let me do that again.
It doesn't get hidden by anything.
This is nothing to hide it's the whole lot of the model is playing and sitting on top of the video feed.
So we want to essentially Mike lockless invisible ground plane that the zombie can climb out of.
So we're going to do a similar thing that we did with the shadows on your trackball.
Let's create a 3-D object and we will add a plane.
So here is our plane.
And that plane will now show up when we press play.
Let's have a look at that.
So let's just get this up.
OK.
So now you can see how that plane itself occludes the zombie when she comes up out of the ground.
But we don't want to be able to see that plane.
We want the real world to act as a surface that the zombie is coming out of.
To do that you'll need the clue to show up that is attached to this lecture.
Bring that in.
Drop it in your assets.
There it is there.
Now we need to create a new material for that.
So material let's call it a clue to and then I realize I've spelt that wrong.
Would just leave it go over to the inspector and for the shade we're going to drop that Dan. Go to and
pick up the clue de Shaila.
Now with that we're going to drag and drop it onto that plane like we did with the shuttle.
It will go transparent.
Now it's not going to show chateaus in this case it's going to show you will not show the zombie when
it's below the surface.
Right.
So let's now play and have a look at that.
So just see if you can sense that.
So when the zombies legs and that are below the ground it will now be clued in and we can see that better
actually if we grab Stevy and attach her to the trackable object and just have a look in the saying
here is that you can only see her arms above this plane.
And then as you move her up just do this you can see how it's being occluded.
So it makes her completely invisible if she is below that plane.
OK.
So let's just take staving off of this for a moment and we'll go back to the trackable.
Now what you can do at this point if we turn our preview on is add other things into this saying as
well.
Now this little glitchy thing that's going on here is because I've got that occlude a plane sitting
in exactly the same spot as that tracker and that's not an issue because you don't see that trackable
object in the scene anyway.
Let's say you wanted something like I had in the previous thing which was like a grave stone and a grave
plot.
We can go to the trackable 3-D object at a cube and then just scale that down.
Until it's kind of grave shaped guess
OK.
And now let's play that and see how we go.
Now obviously it needs to be bigger.
But you can now see how I'm getting closer to climbing out of that grave.
Yeah that's not too bad.
OK so that's working quite well.
Now you might want to embellish it with your own models like I did before and this is really great 3-D
grave package that's in the asset store let me see if I can find it for you because then you can add
all these different things as trees as a church and there's a lot wrought on fences in that as well
which will make you little saying look really great.
So it's just a three day graveyard.
And here it is here.
It's really inexpensive.
What are these.
You know is 20 and you can get all these bits and pieces that come with this is Blanton's in that as
well.
Of course if you just want to follow along you don't want to purchase this.
That's fine.
I'll bring it in and just update mine before I come back and then we'll keep extending this particular
app.
OK.
So I've added my grave and let's just press play might take you a few times to just figure out the exact
location that you need to have it and the crucifix and the plane attached to the Mokka see it yet that's
not too bad.
What we don't have at this point you'll see when she runs off shadows of the so you can bring in your
transparent shutters Civa Shida from before then will create new material which is out transmat
and let's set that to be a transparent shadow.
Ruseva will now create another Pliner is going to duplicate the existing one that's the and then I'm
just going to not rename it just lifted up a tiny little bit and then grab hold of my transmat and put
that on there so that it's just slightly sitting above the occlusion plan.
Let's now have a look.
Well that's going to look like because when these zombies walk off the MoCCA and out into the world
you want them to still be casting shadows on what the pretend world and you can see that that's what's
happened.
Yes.
That's good.
And for as much of the real world that you want those shadows to go over and that you care about that
playing.
Let me just rename that to the.
Plain needs to be big enough to handle.
So you might just want to scale it right out.
So it does cover quite a vast area.
The occlude are in this case.
We only want it really just around this the speed here is all we really care about now I don't know
about you but zombies aren't really scary unless they're on mass.
So let's create an endless supply of zombies coming out of descrive like clowns coming out of a small
red car.
For example we need to write some script to spawn the zombies.
So from this point we're actually going to replace Stevy in the drawer or bowl with something that has
some script on it.
So let's create that script first.
In the essence we're going to create C-Sharp script and we'll call that the sport to open that up and
instead add the default code we want.
It's quite short this program and you can see the whole lot of it on the screen.
So it's a mode of behavior spawn.
It's going to receive a public game object which will be Stavely the character.
And you can do this with anything you'd have.
Or some other animated characters is just a generic Spooner.
The star is going to invoke repasting the spawn method which will start immediately so at time 0 and
then every four seconds it will run again.
So the spawn method is just here.
If you've not used invoke repainting before it's really handy so you give it the name of the method
in quotes when you want it just stop the first time.
And then how often after that and it will just go and go and go until you call a cancell invoke.
Now what this sport is doing is doing the instantiation of the character.
OK so it's not going to be the trackable that instantiates the character any more it will be the code
the trackable will instantiate the code.
So the character gets instantiated at the position of wherever this spawn the object is and the rotation
of it.
I'm grabbing hold of that particular instance of the game object and then I'm just calling a bit of
a row tight on it so I'm going to rotate it around it's y axis it's up vector and rotate it somewhere
between minus 90 and 90 degrees so that they all aren't going in exactly the same direction.
If you wanted them all to go off in the same direction then you would just comment out this line here.
To do that then we have an update which is kind of superfluous we probably shouldn't have an empty up
to sitting around doing nothing.
So with that let's just say it.
Now we'll switch back into unity.
And what I'm going to do at this point in the hierarchy is create a new empty object.
Let's call that spoonbill.
Then on to spawn.
I'm going to drag and drop that script that I just wrote.
And the character here that's come up is going to be Stevy so he puts Davy on to there and then what
do you think we do with the spawn on well yes we could attach it to the trackable as we've done with
the rest of these things here.
Aura we can make it into a prefab and we can put it in the drawer Chabal which is what I'm going to
do.
So grabbing the foreigner I'm trying to get into the assets and then deleting it out of the same select
trackable and then replace spoonbill on to the trackballs drawable so that when the track or the market
becomes visible it's going to instantiate a sport on which will run its code.
And if we just click on that sport or object we can say that it has its code and Stevy is now linked
to it.
So let's run this and have a look.
Wailer at with so SEPA look well OK.
So he's a grave and Stevy is spawning.
So we now have two and three staves but they are spawning at 0 0 0.
Essentially their fate when they spawn is on the top of the grave.
If you take a look at the Stevy prefab itself I click on that over in the inspector you'll see that
it's y value is down.
So it's like minus three point three two.
But when we are creating the spawn.
And when the sport actually sends Stevie Ashe Let's go back into the code.
It's setting Stevie's position to be the position of itself which is really no good to us because we
want Stevie to maintain the prefabs first set height value.
OK so in here instead of this dot transform dot position which is the Spooner's we want the character's
position also.
This would go for rotation as well if you wanted to have the character have its original rotation rather
than take on the rotation of the sport.
Then you would put character in it.
So it's just going to say that let's go back here and we will just play it.
And have a look.
OK.
Now she is coming up out of the grave and we are getting them spawned.
And they will start at different rotations which means that they'll end up walking off in different
rotations because the animations for them are just making them walk forward.
Now in this particular app they're just going to walk off for ever and ever and ever.
We're never destroying them.
If you're running something like this on a mobile device it's going to bog down really really quickly
as is least in the hierarchy builds up.
So we need to add just a little bit more code onto the stage the prefab to make sure that it destroys
itself when it gets out of range of the camera.
Removing something that has gone outside of the camera's viewing volume is really easy because unity
has supplied us with a method to do it on became invisible.
So we're going to use that and write some really short script and put that onto Al-Zoabi.
But before we do that I just want to point out something that I've non-students to lose many many many
hours over because I haven't quite done it the right way.
So he's Stevy.
This is our prefab free-State we now you might be very tempted to put the code on here on this top level
game object to destroy.
When it becomes invisible outside of the camera but it's not going to work on becoming visible only
works on things that have a render.
So if we just open up what's in these prefab we can have a look.
So we've got some rigging which is our hips section and then we've got the zombie girl body if I click
on that and you can see any aspect.
I have a skinned Mischer Indra.
So this object here will make sure that all become visible runs when that event occurs.
We've also got the pants model and there's also a top model all with these mesh Rynders.
So the card could go on any one of these.
You don't want to put it on all of them and you don't want to put it on just them because you don't
want to destroy the body the pants and the shirt all separately because you're going to be left with
the high level game object and the hip's rig that comes with it.
So that's completely useless to us.
What we want to do is put our code on one of these missions and then have that code execute the destruction
of its parent.
So let's go ahead and create a new C-Sharp script and we'll call it destroy zombie then I open that
up.
And inside we'll just replace what's in there with some very short code like this.
So we got the stories on B we have on became invisible and what became invisible is going to do is destroy
this don't transform parent game object.
So we will put this on one of the missions that's inside of that prefab and then it will go up a level
and destroy its parent which will then destroy just everything that's in it.
So just save that switch back to unity.
Now we want to select Stevies body.
Let's put it on the body so will grab the destroy zombie and drag and drop it onto the body.
Just check that it's there in the Inspectah.
OK and now we're ready to go.
Basically So let's press play and get a Mocca in view again.
OK now what I'm going to do is I'm just going to click my mouse on staves so that we can say when this
one gets destroyed.
It has to be out of the Khem reviewing volume in both the scene and the game and you can see it now
it's gone.
So it's working nicely and we won't get a really large build up of all of these clones.
So at the most at the moment now we're just getting like four which is good.
We're not going to overload any mobile device that we end up building this out too.
All right.
So that is occlude is and also a little bit ex-chief as far as optimizing to make sure that you destroy
any augmented characters that aren't being used in the same way anymore.