In this tutorial we're going to make an augmented big step.
We're going to use two markers one for glass and one for tap and have them interact using physics as
you can see in this example here for You'll need the unity package attached to this lecture to begin
create a new unity project.
Add into that bring the package that's attached to this lecture and also the wicked chewed package so
that your assets folder looks like what I've got here now.
The main things that we're going to have.
Ah a cup model.
A cup prefab which uses that motto.
There's two markers.
One is one I've used before and there's a new one.
Both of these markers are trained into this WTC safe which is called height.
Three days you will need to take that and put it into your streaming assets.
We get chewed folder.
So just drag and drop that across into the right spot.
So we are able to find it later on.
Now we also have a tap and the tap pre-fab that comes with that and you get all of the different materials
and there's also the Cluedo Shida and also the shadow Shater as well.
OK and now we're ready to start a project.
So first thing we do is we throw in the Kuchu camera remove the existing camera and then add in an image
tracker.
Now that image tracker we want to set the target collection to the height three day one that I've just
given you now that's going to allow the trackable to take on the value of either the BE match or the
free the image the first one that we're going to work with is the freeby image.
We're going to put a tap onto that so just on teak the beam that so we can work with that while I'm
here and thinking of it let's just go back to the image as well for the concurrent targets.
They're going to have the tap and one cup if you want have two cups then you want to set that to three.
So if you want to print out that Irish pub marker a couple of times then you can use that for multiple
cups and you're Gosain and you'll need to change the number of targets.
OK back to the trackable the trackable is going to display your tap.
So first of all turn on a preview of the tap mark.
There it is there.
And now we're going to go back to the assets and went looking for at TAP prefab which is over here not
the tap mesh the prefab itself.
Drag and drop that onto the trackable to bring it up and you'll be able to see what it looks like.
So it's just a basic tap shape and it's positioned like that.
So you now saying we want it to be so that this is on the back of a wall.
And then the water flows.
Dan so let's try putting some water Spooner's in here to get an idea you want the water spawn to be
wrought there.
So we're going to do now is just create that sport.
Which is pretty similar to the Spooner's we've created before.
So let's create an empty game object and let's call that the spawn.
Then we're going to attach it to that same trackable object and move it so that it is positioned where
the trap opening is where we want our particles.
All the spheres that we're creating in this instance to come out of.
So you know about there is good and you can just that light.
Now we need some code in order to make that beer or SPEEs appear in the same.
So right click in the project create see sharp and let's call it on and then open that up in your editor.
The first thing you need at the top here is a Exposed variable to bring in your pre-fab.
And let's just call it Bowl prefab like that then we're going to create a spawn method like we did before
we went need the Updyke rid of that.
Then underneath the dot add in this.
Then in this day we actually want to invoke repasting of that
painting for the spell on method and let's start it after two seconds and let's have it run every zero
point five if that'll be the speed of the tap.
Basically how often those fees get instantiated.
Now they're instantiated in the spawn something that we've done before.
So we use our preferred that we're passing through.
We're going to spawn at this time we're spawning it at the position of the sport the object itself so
that we can position that sport object at the opening of the tap and then a zero or rotation doesn't
really matter what we use for that.
Then we just make the parent of the Safiya back onto the spoon.
So it's very simple save that.
Let's switch back into unity and attach that to our sport.
That's up here.
So drag and drop that onto the sport.
That's on the trackable.
Now for that it's going to need a ball pre-fab to spawn in the hierarchy.
Right click 3D object and then add in Sofia.
That's phase going to go to 0 0 0 in your scene which is where that trackballs currently sitting.
You want to resize this feature.
So get it to about the size that you want it to be when it comes out of the tap.
So probably something around that.
Now the sphere will automatically come with a Clora.
We want the Sufi's to come out of the tap and then interact with the cup that we're going to create
So that need to have a Clora.
We also want this phase to fall by themselves.
So we need to bring the physics system into play.
In this case.
So with that Safiya add a component in Inspectah and we want to add in a rigid body onto that sphere
and that's going to make it fall make sure that use gravity is ticked.
Which it is by default.
So this is your Safiyah.
Now you can change the color as you like later on.
Grab that sphere drag and drop it down into the assets folder and that will create you a pre-fab that
which you can then feed into your spawn code.
So with this feature let's just delete that.
Go to the spawn.
And then you want to drag and drop your sphere up to it like that.
OK.
We're at a point now that we can test this.
So let's press play and have a look at what we get.
So here's my free b.a.
Let's have a look.
Now what is happening Kite's spawned it.
You can see clearly in the same view over here.
What's going on.
These droplets of spawning in the wrong position at the sport of location but they're falling under
gravity and gravity happens to be as it usually does going downwards like this.
Now why do I have my top facing like that and not above it.
It would then come down.
The reason being is that this being met matka would then when it sits flat on the ground be able to
show the test.
But in this case I've got these B Matt Mocca sitting on a wall which is where I want it.
So that means we just sort of change the way that this physics system is working.
We want the physics to go down the zid axis in the positive direction along the Zed axis.
Now that's quite easily fixed.
Stop flying.
We're going to go into edit in the main menu project settings and down to physics.
Now we go over to the inspector have a look at gravity it's at to zero or negative nine point one which
is going in a negative direction down the y axis at the acceleration of gravity which is nine point
right one.
And this time instead of going down the Y we want to set it to zero in the Y and we're going to go along
the positive direction of the Zed by nine point one.
All right.
So we can now play and have a look at the result.
OK so let's get at tap and pull it out.
There we go.
All right so the next thing to do that we've got is tap going is to add in our cup for the Cup.
We need another trackable.
Select your current trackable and control day to make it duplicate.
Then you just want to delete this corner and the tap that's under that and I'm going to use it.
Select that track.
Well let's call this cup.
Give it a different name.
While we're at it we should also name our other trackable tap.
All right.
So select your cup the cup is going to be the other mock us.
Switch that over.
And to the cup it's going to display the cup pre-fab.
Now you can put that in as adorable.
Or you could attach it to the Cup.
We're going to put it in as a dribble this time so fahn the cup pre-fab which looks like this.
And it looks like this because it has a shared pipeline in occlude or underneath it.
And just drag that in there.
But to see that in action if we click on the cup and we preview the Mokka for in the scene and then
drag another copy of that cup prefab onto it they can see the cup and how it's sitting and the fact
that they shed I plan in the Cluedo itself is sitting flush with the Mokka.
So if the bowls as falling down fall over the cup then they will roll across America and then go full
Danna and off that Mocca which is a nice looking effect it means that the cup will then look like it
is being held above a surface and that the bulls are interacting with it.
So OK we've got that.
You can now deflate that cup if you added that in.
And we are ready to try it out with the cup so that's how easy it was to add the cup.
Now the cup if you have a look at the cup and go through here for the actual object itself you'll notice
in the inspector.
Besides it's Mish render is that I've also added for you I mesh Collider which means that the cup will
be able to physically contain the balls as they fold down into it.
OK so let's play and then we're going to need to find out.
Tap.
And then we need a market to pick up our cup and you'll be able to then a lot know like that and fill
the cup up with those fees.
So that'll just keep going and going until they get full enough which point they'll eventually spill
over the edge.
And they're starting to bounce it now.
You can also pick up this cup and tip the contents.
Ash
like that.
And because I've got hold of this second cup marker and I set my targets to have three then I can pick
up an extra cup if I can get my camera to find trigger and hold that.
And they try not to cover up any markers that might be in the road to the right spot to fill up that
cup and yet tip the mount if you move it too fast of course the physics system won't let the fact that
you're trying to collide things too much and you'll lose it all.
Now before we can actually say this is kind of ready to deploy we should take care of this.
These low wages constantly and forever generating those fees out of the tap.
So at some point it's going to really build the system down with an awful lot of SPEEs.
We need to make sure that they go away when they're out of the camera view in the assets.
Let's just right click Create say shop script shop scripts let's call it remove Safiyah then to that
let's open it up.
We're going to add in some on in visible code and get rid of the existing ones in there.
So this will be weighed on became in visible and inside they we will run destroy on this game object.
That's going to be attached to the sphere and when its mesh becomes invisible goes outside of the viewing
volume of the camera it will get destroyed for us and clean that up.
So just save that flick back into unity.
Now you need to find your Safiyah which is here.
That one there and then drag and drop that remove Safiya code onto it.
And then just make sure it is on nature Chicot it is there.
And now when the fees disappear from view that will also disappear from your hierarchy.
So we can press play and just check that out again use our marker find out have this.
Now these fees are being childhood to our temporary fab or sport on this Borna.
And you can see in the hierarchy the city is being created and then being destroyed when they go outside
of the camera of course when you start capturing them in the cup just move that but grab a cup you're
going to get a lot more of them staying alive for longer.
And you can see them building up their.
But then we can just do the math.
All right.
So that is using the two markers to create some kind of physics interaction between them and I hope
he enjoyed putting that together and I'm sure he can probably think of a whole bunch of other things
that you can do now that you know how to combine Marcuse and physics properties together because remember
each of those objects the tap.
This is the cup they're all in your game.
So there's no reason that the physics can't interact between them is just a matter of getting them law
and correctly.