For this assignment we'll be using the
empty scene in the robot lab.
Open the empty scene and then to make
sure that we maintain our empty scene
go to File - Save Scene As
save it in to the Scenes folder
and we'll call this Bouncing Ball.
As usual Unity takes you straight into the
scene that you've just saved, so we're now
working in the bouncing ball scene.
A good first thing to do in Unity is
make the classic bouncing ball that you
may have done in other pieces of software.
In the models folder we have some
primitive shapes, such as the spherical
'samoflange' and the cubic
'power cube', as well as a number of other
different assets.
>From the models folder, drag and drop
the 'prop samoflange' object in to the scene.
Remember that you can use the translate tool
to select and move it around.
This can be done by dragging the handles
or by dragging the planes on the object.
You should notice that I'm using the F key
to focus on that object and move the scene
view in to focus on it too.
To make sure that our object is lit by our
dynamic lights make sure that the layer
of the samoflange is set to Dynamic Objects.
Now you should see that our object is
nicely lit and in the mesh renderer
we can also check 'Use Light Probes'.
Now our object will be properly lit
within the scene.
Next we'll add a rigidbody component
so click the Add Component button
on the inspector and go to Physics -
Rigidbody.
However we can't use a rigidbody
without a collider.
So let's go to Add Component - Physics -
Sphere Collider. This gives our spherical
object a bounding area and if we zoom in
you should see that there's a green outline
going around it. Looking at the rigidbody
you can see that we have
properties for mass, drag, etcetera
and also a checkbox for Use Gravity.
By default this is checked and that's
exactly what we want to do here as well,
and what we'll also do is effect the kind of
friction that we want this object to have.
By default if I press play now
the object will fall to the floor
but what we want to do is add in a friction
response too. This is handled
by the physics material on the collider.
So we're going to make a new physics material
so I'm going to select the Assets folder
and then we'll make a folder for this,
so click the Create button and choose Folder
and make a new folder in which to store
physic materials.
Then because we want to create this
physics material inside that folder
select the folder then go back to Create
and choose Physics Material.
This creates it inside the folder.
And as soon as you create it you can then
name it, and you should name it Bouncy.
Because that's what we're going to create - a bouncy ball.
Before setting up this asset I'm going
to apply it to the object so that we don't
forget later. So reselect the
prop samoflange and then drag Bouncy
from the project panel and drop it on
to the physic material setting
in the component in the inspector.
Now reselect the asset in the project panel
and we'll take a look at it's settings.
You can see here that a key one that we
want to play with is Bounciness.
And I'm going to set this to 0.8.
Now if I press play what you'll see
is that it bounces to a halt.
The reason for this is Bounce Combine.
Because what this does is average the
friction on the object and the
object that it's colliding with - the floor.
So whilst I've set this to 0.8
because it's averaging the two, what we're
actually getting is 0.4.
So what we'll do is set Bounce Combine
to maximum. Do that now.
Then you can test out again by pressing play.
And now that you can see that it has
more bounce to it.
But if we want it to keep bouncing forever
we should set Bounciness to a value of 1.
And we're going to make things a bit more
interesting now. With our object
roughly in the middle of the scene
reselect it and choose the Translate tool.
Remember you can use W on the keyboard
to select that tool at any time.
I'm going to drag it up so that it's a little
high and then from the Models folder
I'm going to locate my bench.
So grab PropBenchWork
and drag that in to the scene.
Yet again I'm going to put it on the dynamic
objects layer and I'm going
to go in to the mesh renderer and
choose Use Light Probes so that it's
nicely lit by our dynamic lights.
Then what I'm going to do is add a collider
because we're going to make our samoflange ball
bounce off of the bench.
So I'm going to go to Add Component - Physics
and nice and simply I'm just going to add
a primitive box collider to this.
Then hover your mouse over the scene view
and press F to focus on the object
so that we can see it a little bit closer.
Note that at various times I am holding
down the Alt key on the keyboard to orbit
around as I drag.
Now I'm going to go to the Hand tool,
to effectively hide the translate handles
and I'm going to hold down Shift to adjust
the boundaries of the collider.
The reason I'm doing this
is because I don't want it to bounce off
of the top of the collider here.
I'd rather it bounced off of the surface.
So all I'm going to do now is hold down Shift
and drag the top one
until it's roughly in line with the top of
the work bench mesh.
Now what we're going to do is go back
to the Translate tool
and I'm going to drag this upward,
something like that.
And now what I'm going to do is
tilt it at an angle. So I'm going to go
to my Rotate tool,
which remember is E on the keyboard,
and I'm going to tilt it
something like that.
Then all I'm going to do is switch to
an overhead view, so using the View
gizmo in the top right of the scene view
click on the green Y axis spoke.
And then I'm going to reselect my
spherical prop samoflange
and I'm going to get my view in order
and then I'm going to drag with the
Translate tool until it's over the top.
Note that I'm still in a perspective view
and if I want to go to an orthographic view
I can click the cube in the middle, like that.
So now if I zoom in
I can see exactly whether it's over the top.
And I'm going to keep using the Translate tool
to position it where I want it.
And remember that we can rotate round
to side-on views as well to ensure that
we're getting it in exactly the right place
and keep rotating around until we're happy.
Then I'm going to click on the white cube
in the middle of the gizmo to go back
to my perspective view.
Now all I'm going to do is press play.
And as you can see our samoflange ball
keeps bouncing around all over the environment.
And that's it.
Remember to save your scene, and keep
experimenting with the different values
in the physic material asset to get
different effects,
or refer to the Physic Materials lesson
for more information.
Subtitles by the Amara.org community