‫Welcome back.
‫In this video, I would like to add an eye to my player to record.
‫And this is a little challenge.
‫You can try it yourself.
‫And I would highly recommend to do that.
‫So this way you will learn how to move something yourself by code.
‫You have done that already, but now you will do that in a little different way and you will follow
‫along with the ball, for example.
‫So post the video, try it by yourself, and once you're done you can check out how I've done it.
‫And if you're not interested in the exercise at all, you can also simply watch how I do it.
‫All right, so let's get started.
‫We need to add another script to our record player, too.
‫So I'm going to create a new script.
‫Which I call record player to a.
‫And now the question is, what does this record player to I need?
‫Well, it needs a speed and then it needs to follow along our ball.
‫So the means we need a a movement speed which is a float movement speed.
‫And we need the ball to follow.
‫So public game object ball.
‫And now within our fixed update method, we can check where is the ball and where are we?
‫So if math f which is a collection of common math functions dot EPS.
‫So if the absolute value which means it doesn't matter if it's a negative or a positive value in the
‫end, well the result will be a positive value.
‫So it returns a static float.
‫As you can see, it returns a float here.
‫So we call the EPS function and here I transform the position of my self.
‫So this dot transform dot position and subtract the position of the ball.
‫So ball to transform the position thought y and I should use y by my by my own as well.
‫I calculate the y value of the racquet of player two minus the y value of the ball.
‫And if that value is higher than 50, then do the following.
‫So first check if the ball is higher than the record.
‫So if transform dot position that y is higher than ball, don't transform that position y.
‫If that's the case, then get the component.
‫Rigid body rigid body to DH.
‫And change its velocity to a new vector two, which is zero comma one, and the one means the y value
‫is positive times, the movement speed.
‫So in this case, it just says if the ball.
‫Because further than 50 points higher than our record.
‫Please move the record up and else please move it down.
‫So we just copy that code here, we enter it there and now we use minus one.
‫So now please move it down.
‫And if this statement here is not true, then we have an LS and here we just say, please don't move
‫at all.
‫So we say get component and we reduce this movement speed here and enter zero.
‫So that means the velocity of our racquet will be zero whenever the distance from the ball to the racket
‫is lower than 50.
‫Not the distance in general, but the Y position distance.
‫All right.
‫So now that we have that, we can save that script.
‫We can deactivate our racket player to script, change the movement speed of our eye.
‫So let's save the scene and then we will see.
‫Okay, here, movement speed.
‫Let's do 200 and let's drag the ball in there as well.
‫All right.
‫So now let's check it out.
‫The ball moves.
‫And as you can see, the I, I don't press anything.
‫The eye follows along and whenever it's 50 points or higher, then it moves along and then we are game
‫over.
‫Great.
‫So we have an eye for our play to and that's great.
‫So now you know how to create a very, very basic eye.
‫It's even too much, almost to call it an eye, but it does something on its own based on the input
‫that it gets.
‫Great.
‫So see you in the next chapter where we create the next game.