In the last lecture I left you with a challenge to figure out how you could spawn zombies on a particular
arc around the fourth victim of the camera.
So let me show you how you can do that.
Back in the control lock in this Bourne zombie we need to control where these Zayd pause is around that
Ford ficta.
So the forward vector going straight out from the camera we need to sort of rotate it one way or the
other by a random amount to do that.
You only need to put in one line of code so how did you go with that.
Let me show you what it is.
So we have Zed pause.
The victor is going to equal its self multiplied by a turn in Daut angle axis call.
What this does is rotates a vector if you multiply by it giving it a random angle to multiply and multiply
turn around.
So in this case negative forty five and 45 is going to be one way or the other.
And we're turning around the vector which is going to keep a vector Noss horizontal.
Something really interesting I'll just point out with this equation is that you have to do it with the
multiplies it pulls on the end.
If you put Zayde pause at the beginning and put multiply it it's not going to work.
Give me the wrong value and that's because the way that Catoni in mathematics works with vectors.
So you always have to have the angle axis first multiplied by the Zippos.
Right so that's then let's say it and go and have a look at the behavior.
So press play and then I will start tracking.
We should start to see our zombies being spawned anyway from this kind of angle out here to around here.
And you can see I'm starting to feel in that arc and if we can look up with the camera we'll see them.
Calming won't they quite close now coming towards us.
Rights.
Or stop playing.
It's now time to get these Sophi is making them lethal to the zombie.
Now we do that in our chase code.
So let's go in the end and we will begin by putting in an on trigger and a method.
We have a collider on the zombie.
And if I just switch back and show you the pre-fab full the zombie itself you'll see that the captial
Collider has is trigger.
This is not on by default.
If you're creating your own character from scratch to make sure that that is tweaked in order for on
Trigger into to fire when there is a collision.
So let's add that in and it looks like this.
So to stop the zombies triggering a death as such when they hit anything.
We're going to first test what we've collided with so what we collide with what they collide with comes
in is Kolata.
We can then check the tag on that Kalat is equal to SPia because remember all of Ecevit objects have
that tag set and they sit on the prefab if it is a city that the zombie gets hit by.
Then we run and destroy this game object which will get rid of the instance of the zombie that this
card is on.
So let's say this.
And now I'm ready to try it out.
OK let's press play and we will this time start trekking from the flat.
So stop trekking and let's just go up a little bit so we can see the zombies coming in.
Like I can see their feet but you'll see these fees.
Now if a sphere hits a zombie it creates like a whole bunch of them.
Of course when you're doing this on the mobile device you'll be able to turn the mobile device and tap
on the screen to create these fees.
But notice the fee is destroying the zombies when they hit them.
So just watching these you can see them popping out of existence as it comes in now to enhance this
further.
We could make the zombies go into a death animation.
So let's do that.
Back in our chase code what we're going to do at the top.
First of all is we're going to add an animator called and this is going to get hold of the animator
that's attached to our Zombi of which there is on this prefab but I've given you so these start get
components
and I might like that.
Now what are we going to do with this matter.
Well in on trigger Antar if a sphere has hit us we're going to run one of the trigger is or course one
of the triggers to go off so set trigger hit like that that will cause the zombie to go from the walking
animation into its death animation.
Now if you're not familiar with the mechanism system in units the trigger is something you set yourself
so I created this name.
I'll just quickly show you that even though it's not really the focus of this course this is your animator
if I double click on that and open it up you know we end very quickly.
You can see that there's a walking animation and there's a zombie drawing animation over in parameters.
I've got something cool heat and this is what we're calling in sick.
Trigo back in the code.
And if you select these transition going from one animation to the other and then go over to the inspector
you'll see that the condition set is hit.
So that's how that hit comes from the code into this parameter settings and triggers this to a coach
who might the zombie go from walking in a motion to going to these dying animation.
Right.
So let's go back into our code and finish this off.
Now the issue with this is if you sit the trigger to hit and it starts running the death animation what
then happens.
Well it's getting destroyed.
So it doesn't even have time to run a death animation.
So instead what you should do is destroy it after a certain amount of time.
So in this case I will just give it five seconds and then destroy it.
Another issue that you'll find here is that the zombie will go into the death animation but the collider
will still exist.
So what you want to do is turn it off.
So this component Kaleido
enabled a Cool's false and that will make sure that that collider isn't affecting anything while the
zombie character is still dying and lying around in the environment.
So let's just save that and we'll have another go.
So let's go back.
What I'm going to do in the scene is just that a little bit and come in closer because you get a better
sense at least in the editor of what's going on in the same view.
Makes it a little hard when you're not using your mobile device to see what it's going to really look
like in the end.
In this editor.
Right.
So play spoons zombies.
Let's now just shy and slowly come up in find with so I go there.
And now since I'm balls out to try and kill them and I'm having a bit of success here you can see them
going into the death animations.
And they're falling over you can see that from the bulls there so there's still a few problems of say
when they actually die which is a common sort of thing to think about is that the card on them still
making them turn towards the camera.
So even though they're dead they're still moving.
So this is actually an easy thing to fix so let's stop playing and we'll just duck quickly back into
our Chase card.
Any idea we're going to go up the top and credible and say dead equals false.
Now they will become dead when they've been hit by a sphere.
So we put that down into here.
Did equals truth.
And finally we just tested in the update so the update is the thing that rotates the character around
as the first thing in the upper deck will go if dead return.
And that will stop this code from running.
Let's save and have another little look at what we get.
Press Play start everything up
should have checked the camera from below.
I'll start it down here.
And
press play and start everything off.
Move the camera up a little bit.
It's
it's not too bad it'll do.
Now I can just shoot these selfies.
Ouch.
And now they're dying in the sport and their rotation.
You can say these ones he isn't changing and they disappear after a certain amount of time.
Right.
So that's good.
The other issue you've got now is that the fee is you're going to end up with and have a look in the
hierarchy an awful lot of spheres because they're never getting removed.
Now you can't use an on became invisible for the series because as soon as you turn your camera to look
in a different direction for your augmented reality and something goes out of that view it's going to
get destroyed which is not what you want.
You still want existing in the environment.
So one way to deal with this is to destroy the cities after a certain amount of time so let them leave
for like 10 seconds and then just get rid of them.
So let's just stop that.
What we will do to sit that is in the controller code.
So let's go in there and where we create the SPEEs is when we click that's going to be done here.
So his Aunt Sophy where we're adding the force to it what we can do at the point that we create this
fire is go new
the game object and it's already a game object so it's kind of a little probably superfluous sign that
is a game object but let someone undestroyed after ten.
Now I'm writing this code backwards here and we're going to go destroy the like.
Ok so I will destroy it.
We create the ball and we destroy it 10 seconds later after being created so that makes that little
clean up quite easy for them.
OK.
And now we're at a point where we can build it out to our mobile devices and test it out in a more realistic
scenario than we can get in the editor and you will see how much more accurate and smooth everything
is OK.
So don't forget the wicket you're going to need your license key added and the bundled day will need
to be added into your player's settings.
Of course you'll have to switch over to whatever mobile device you're using for your platform.
If you didn't at the beginning and give it a bit of a go.
So I'll be back in a moment to show you what it looks like on my Android device.
All right.
So here's the app loading on an Android device the first thing you need to do is align the grid with
the surface that you want to put the characters or the augmentation on.
You can also use the slaughter at this point and see how it works to raise and lower the grid once you
have it where you want it.
And it's a pretty much good representation of the real world plane.
Then you can press start tracking and you can see that I've got these zombies walking across the floor.
Now it's really good if you've got your distances right in some of these zombies because they're kind
of far enough back along that plane that they had to fall back for the amount of floor that I've got
so they tend to look at that point like they're floating above the furniture.
But for the ones that are actually on the ground and within that floor the real floor plane they do
look situated and at those speeds you can see them themselves when they first appear in the scene situated.
But as I roll further away and then on to other objects of furniture rather than the floor then they
look like they're floating in the air.
So if you were to make an augmented experience that was to apply on a table top then you'd best be make
sure that your virtual environment isn't going to extend that and then make the whole application look
like that it's unrealistic.
So that's instant tracking and how you can get it set up on your mobile device to create experiences
that don't require the pre-prepared markers.
We looked at in the previous sections.