Back in this video.
We are going to take care of our ball.
So far, our ball is really just this little square here in the middle.
And we need to change the functionality or we need to add functionality to him so that it flies from
left to right, back and forth whenever it hits a record.
And of course, we also want to have this bounce in it.
So it should bounce off the racquets and bounce off the top and the bottom wall.
It shouldn't bounce off the sidewalls for now.
But we will add that functionality just for testing purposes right now.
So let's go ahead and change our field as our ball needs to have a collider, which it does.
And what we need to add is a material.
So far we have no physical material for our ball.
So what it is right now is simply a collision dot.
So that means that if something goes towards the ball, it will collide with it.
If you want the ball to move, we need to add a rigid body.
If we want the ball to bounce, we need to add a physical material.
So let's go ahead and create the rigid body first.
So I'm just going to add a physics to the effect.
And if I want to do that, if I want to use a physics to defect effect, for example, a rigid body
to DX, I will run it to an error.
So let's try that.
You can see I can't add due to a conflicting component, which means our Box Collider currently is a
3D box collider and a 3D box collider can't work with a 2D rigid body or with other 2D components.
So that means we need to remove that component, remove our box collider and add a 2D box collider.
So there is a 2D box collider here, as you can see, and that's what we want to use now as the offset.
There is a very small value here.
I don't want to have any offset at all, so let's get rid of that.
So I go for zero here and now I will add a 2D rigid body.
So rigid body 2D, which is the component which adds, for example, gravity, it adds a mass.
Well, pretty much it makes it a physical object.
So now it's not just the wall, pretty much what the ball was before with its collider.
But now it's actually a physical object which can be dragged down by gravity, which can be influenced
by physics.
So now let's go ahead and create a physics material.
Let's go with that.
So we go back to our assets, we go to materials, and I'm going to create a new physics material to
DX.
And I'm going to call that one bull.
You could, of course, call it ball physics material or something like that.
I'm just going to keep it simple.
That's the physics material that I want to use for my ball.
Now that physics material has two different values one of one for friction and one for punchiness.
The friction is pretty much how.
How much does it wear of how much does the speed wear off when it, for example, rolls or slides over
another surface?
As we don't want to reduce the speed of our ball at all, we need the friction of zero.
Now, the bounce in this means how fast or how strongly does it bounce back when it falls against a
different collider?
And here we need one because we want the ball to go with the same speed afterwards.
We could, of course, say 1.1.
That means that each time it bounces, it goes faster.
But that's not what we want.
We want to go for 1/1.
So now that we have the physics material for our ball, we can drag it into its box.
Collider So let's drag that right in there.
So if we test that now and I'm going to use a gravity scale of 100 to speed it up a little bit, we
will see that our ball will not do nothing.
Well, it will drop, but it will not collide with the bottom, not with the bottom wall, at least.
And that's because our bottom wall as other walls has a box collider and not a box collider.
2D because our ball has a box collider two D It doesn't collide with 3D colliders.
It really doesn't care about those three D colliders.
It only cares about 2D colliders.
So what we need to do is replace the colliders of all of our walls.
So I'm going to remove that component and I'm going to add a physics to the Box Collider component.
And that's what I'm going to do with the wall, top wall, bottom wall left wall right and wall left.
So let's remove that component, add a box collider and do the same thing for all of them.
And next, physics two D Box Collider and same here remove component box collider two DX Add Component
Box Collider to DX.
All right.
So if we test that now, our ball should bounce off.
As you can see, it bounces off our bottom wall and it does that with exactly the same speed as it did
before.
So it's influenced by gravity now.
That's good.
We will need to change that later on, as soon as our ball flies from left to right.
So now what we could do is, for example, just for your taste testing purposes, we could change the
bounce in to 1.5, for example.
Now we see our ball bounces off faster than it did before and it drops down, drops off our map as well.
So let's go back to bounce in this one.
So it will bounce off the same speed and height that it did before.
Now that we have seen that we need to dx physics colliders for our the objects that need to be influenced
by the ball.
We need to do the same thing with our rackets.
So let's go with the records or change the records.
Here we have a box collider here.
We need to change that to being a box collider to DX.
The same thing with the record to remove the component and add the component physics to the box.
Collider So now you see those weird offset numbers and those values.
What really matters is that the collider has the same size as the game object itself.
That's what we get here.
So let's reduce the offset, change the size to one and do the same thing.
For our record, we don't need any offset and we just change it to one times one.
Now our ball should bounce off the records and in order for our ball to fly from left to right, we
need to add a script to the ball.
Because so far it only is influenced by physics, which is based on this gravity scale that we have
here, and we are going to change that in the next video.
So let's go to the next video where we will add the script to our ball so that it flies left and right.
See you in the next video.