Welcome back.
In this video, we are going to take care of our records.
So far, we can't move them and that's what we want to change in this video.
Therefore, we need two scripts, one for record player one and one for record player two.
So let's add a component, a new script, and I'm going to call that record player one.
And the record player to script is something that you will do that you should try yourself.
So let's go ahead with the record player one script first.
What we will need in here is very simple.
It's really just one thing.
We will need the fixed update method, which will constantly check if the user presses a button and
if he presses a specific button, then the record should move and the record should move with a specific
speed.
So that means we need a public float movement speed value.
A good value here would be 200, for example, so that the player can move the record with the speed
of 200.
Other than that, let's create a fixed update method here.
It's an internal method from unity and it will be called a fixed amount of times per second.
So for example, 60 times per second.
Now what we need to do is check if the user pressed a button and save that within a float value.
So I'm going to save that into V, which is our vertical value and it should get the input of our user.
And the input I want to have is the access row, which that does is returns the value of the virtual
access identified by access name with no smoothing filtering applied.
So it doesn't change.
It doesn't matter if you press hard or soft, it will simply take the raw value and it will simply,
if the user pressed, let's say w it will go up.
So the record will go up.
So that means the value here will be one.
If it is, if you press this as the value will be minus one.
So the record will go down.
And now of course we need the access name.
And how do we get that?
Well, I'm just going to enter vertical here, which are the vertical axis.
But how we do that, how we get that is within unity.
We can go ahead and go to edit project settings input.
And there as you can see here, the input manager opens on the right hand side within the expect inspector
and you can see that there are 618 axes and one of them is vertical and that vertical axis is what we
want to use.
So it says here down up as w this is the vertical axis.
But what I want to change is I want to have a vertical axis for player one and another vertical axis
for the player too.
So, so the arrow keys are for player two for example, and SE and W are for player one so that we can
play on the same keyboard.
And for that we need to have another.
Input.
So you have vertical here as well.
That's not what we want.
I want to change the size, so I'm going to change that to 19.
So that means I get another one here at the bottom and I'm going to call that vertical two and down
and up will get deleted from it.
So I'm going to say the negative button will be down and the positive button will be up.
And here.
The all positive button.
We don't need that.
And the other values I copy from our vertical.
I activate snap here at the bottom sensitivity three should be fine.
Gravity three should be fine as well.
So now we have an axis called vertical and another axis called vertical two.
And the vertical one should be four.
Play one, and the other one should be for player two.
So that means I need to change this one to be S and W and the alt buttons will not be used.
So we don't have alternative buttons.
It's just S and W for player one.
All right.
So we have the axis one that we created ourself, which is called vertical two and one that was there
already, which is called vertical.
And we changed that a little bit.
Right now that we have that, you see, we take the vertical axis here, which is the input that we
just changed.
Now that we have that, we can go ahead and change the speed of our racket.
So we get the component which is our rigid body to DX of our racket and we change the velocity to being
a new vector two, which is zero and as the y value V multiplied with movement speed.
So that's the whole script for our record player one.
Now let's have a look at Unity again and let's see if we can make our record move now.
So record player one has the script, record player one which is good.
Now what it has is a box to DX Collider, so that's perfect as well because that's what we want to change.
But it doesn't have a rigid body yet.
So let's add the component physics to DX, rigid body to DX, and we don't need gravity here.
That's important.
Now we of course need to change the movement speed.
So here our record player, one script has a movement speed let's try 200 and now let's test the game.
Let's see if our racket can move.
And as you can see, I can move my record on the left hand side.
So now please go ahead and try the same thing with the record too.
So do all of the procedure that I've just shown you and reproduce that with our record too.
And as you can see, my record is a little bit influenced by by the ball's physics.
That's not really something that we want.
So we will need to add constraints to it because currently it's rotating.
And I don't want it to retain a rotate.
So I'm going to freeze the Z position and the ex position of my racquet.
So now it shouldn't get dragged to or pull pushed to one or the other side.
And as you can see, it's stiff now.
All right, please go ahead and try to do the same thing with the record player, too.
So pause the video, try to reproduce what you've just seen and check out with it works.
All right.
I hope you tried it.
So we need to create a new script, which I'm going to call record player two.
I'm going to open it up in Unity and I'm going to copy all the code from here and paste it in here.
So what I'm the only thing I'm going to change is I'm going to change the axis, which is now vertical
two.
So that will take the up and down arrow in order to move the record.
The rest can stay the same because it's really just the Y value and that should be the same functionality
for both records.
Now that we have that, we need to add a rigid body to.
DX, I hope you managed to do that.
So let's add the rigid body to the two R record.
Let's get rid of the gravity scale.
So enter zero and let's add the constraints for the x and z value.
So only y can be changed by our player.
Now we of course need to change the movement speed and if we wanted to be unfair, we could give 300,
for example, to our player two and only 200 as the record movement speed for a player one.
And that would make it highly unfair because as you can see, I'm going to use the buttons at the same
speed.
And once again, as you can see, the left is not going with the same speed as the right record.
So that would be a way to cheat the game a little bit or to make it harder for player one or two.
All right.
So if you would like to play the game, let's say with your three year old brother who can barely hold
the controller, that would be an option to make it fair so that your record is slower than his and
he is more likely to hit the ball that way.
All right.
I hope you manage to do that.
It wasn't really too much functionality to add what was really important to add the script copied it.
The code change, of course, the input.
So within the project settings you had to change the input.
Of course you had to create vertical too.
And then of course add the movement speed, add the rigid body to DX and so forth.
Great.
So now let's clean up a little bit.
Let's drag those two scripts into your scripts folder and let's save our scene.
And in the next video, we are going to have a look at the physics of our records, because so far the
ball only goes left and right.
It doesn't really care about whether it hits the record at the top or at the bottom part of it.
Because what I want to have is if it hits it at the top, then the ball should have a different Y value.
So it should go towards the top.
If it hits it at the bottom, it should go towards the bottom.
That's really important for Pong, otherwise it would be a super boring game.
Great.
So see you in the next video.