‫Welcome back.
‫In this video, we are going to create the resetting functionality.
‫So that means whenever somebody scored the ball gets reset to a specific position based off of whose
‫turn it is.
‫So if it's player plays one turn, it will be on the left hand side.
‫If its play is to turn, it will be on the right hand side.
‫So that's what we want to do.
‫And of course we also want to have the game over screen, so we want to go to game over at one point.
‫All right.
‫So in order to get all of that done, let's go to our scripts.
‫And the ones that are relevant is the ball movement.
‫Then our collision controller and our score controller.
‫Those are the three scripts.
‫All right, so let's go into a ball movement script in here.
‫We need to go ahead and reposition the ball.
‫We need at least a method in order to position the ball correctly or reposition the ball.
‫So I'm going to create a new method.
‫I'm going to call it position ball and it needs a Boolean in order to know where the starting position
‫should be.
‫Is it player one or is it player two who is starting?
‫So I'm going to call it is starting player one.
‫So whenever we want to start the game, we first of all want to reduce the velocity of the ball.
‫So it should go back to the velocity of zero.
‫So there should be no velocity at all.
‫So we say this dot get component and we want to have the rigid two body, rigid body to DX.
‫And of that we changed the velocity to a new vector to which is zero comma zero.
‫A velocity of zero towards both directions is no velocity at all.
‫Now if it's player once turn, so if starting player or is starting player one is true, we want the
‫ball to be at a position.
‫So game object dot transform dot local position which is a vector three variable is a new vector three
‫at -100 zero zero.
‫So that means the ball will be just left off the center.
‫And if it's not player one who is turning this, then we want it to be on the right hand side.
‫So we copy that code and say positive value 100 for the X value.
‫So that method will simply position the ball correctly whenever we restart the game, for example,
‫or whenever somebody scored.
‫And that's also something that we should call whenever we start our ball.
‫So that means we go here, dot this position ball and we hand over the starting player variable.
‫All right.
‫So now that we have that, we have to check out our our collision controller, because in here, if
‫the ball hits the left wall, we want to start a CO routine, start co routine, this dot ball movement
‫dot start ball.
‫And here we need to hand over a boolean.
‫Or we can at least and I'll just say true.
‫So that means the ball should start on the left hand side and we do the same thing if it hits the right
‫ball.
‫So if it is the right ball start KO routine this ball movement start ball and in this case a false.
‫So that means that our starting player is false and if our starting player one is false, that means
‫player two starts.
‫All right.
‫So now that we have that, let's check it out.
‫Let's see if all is working fine.
‫So let's lose the first one.
‫You see, the score is increased.
‫The ball is at the left hand side again.
‫Now let's check it out.
‫Let's go towards the other side.
‫And there's one point and at the same time, it's player to turn.
‫All right, so whenever somebody scores, the other players turn starts, great.
‫So we have that.
‫We have the resetting of our ball.
‫Now what we need to do is, of course, we need sound and we need a game over scene.
‫And I would say it's best if we do that in the next video.
‫So just a quick recap.
‫What did we do?
‫We create a new method within ball movement which positions our ball and the based on whose player's
‫turn it is.
‫The ball is on the left hand side or on the right hand side.
‫At the same time, we stop this the speed or reduce the velocity of the ball to zero, comma, zero,
‫and whenever we collide with the ball.
‫So whenever the ball collides with the ball.
‫So we reposition the ball here with our start co routine.
‫Great.
‫So let's see you in the next video where we will use our score controller in order to go to the game
‫over screen.
‫And also, of course, we will add the game over screen.
‫So see you there.