WEBVTT

00:00:01.790 --> 00:00:04.180
Hey every one, Adam Tuliper
here with Microsoft and

00:00:04.180 --> 00:00:07.340
I'm here to bring you
the second installment in our

00:00:07.340 --> 00:00:09.680
introduction to physics
with Unity series.

00:00:09.680 --> 00:00:12.900
Physics can be a daunting task
in Unity, so I recorded episode

00:00:12.900 --> 00:00:14.870
one previously at
a conference I was at.

00:00:14.870 --> 00:00:17.100
I'm back home in my garage
actually to record you

00:00:17.100 --> 00:00:18.270
this episode.

00:00:18.270 --> 00:00:19.800
The link's here for episode one,

00:00:19.800 --> 00:00:23.320
which was GameDevShow14,
Intro to Physics in Unity,

00:00:23.320 --> 00:00:26.250
so watch that first before
you watch this one.

00:00:26.250 --> 00:00:29.150
And then come back to us and
leave off right here.

00:00:29.150 --> 00:00:30.155
Let's get started, shall we?

00:00:30.155 --> 00:00:40.155
[MUSIC]

00:00:43.142 --> 00:00:44.967
Hopefully you've either
watched part 1, or

00:00:44.967 --> 00:00:47.200
are familiar with all
the concepts from part 1.

00:00:47.200 --> 00:00:48.600
So let's get rolling on part 2.

00:00:48.600 --> 00:00:51.040
I'm gonna talk about kinematic
ridgidbodies in this.

00:00:51.040 --> 00:00:52.500
In other words,

00:00:52.500 --> 00:00:54.760
objects that you take out
of the physics simulation.

00:00:54.760 --> 00:00:57.330
But they still kind of act
like a physics object.

00:00:57.330 --> 00:00:58.480
Why would you do that?

00:00:58.480 --> 00:00:59.910
Stay tuned.

00:00:59.910 --> 00:01:02.750
Interpolation, how
various moving objects at

00:01:02.750 --> 00:01:05.200
different speeds can be
handled differently.

00:01:05.200 --> 00:01:07.620
Super fast objects can teleport
through other objects.

00:01:07.620 --> 00:01:09.490
So we'll talk about
those settings.

00:01:09.490 --> 00:01:12.080
Also how you can use
physics materials

00:01:12.080 --> 00:01:14.430
to handle things like
friction and bounce.

00:01:14.430 --> 00:01:16.390
Also, a very common
technique called raycasting.

00:01:16.390 --> 00:01:17.460
How do you know what's
in front of you?

00:01:17.460 --> 00:01:19.210
How do you know when
you hit an object?

00:01:19.210 --> 00:01:23.175
Or how, when some other
object in your scene, an NPC,

00:01:23.175 --> 00:01:26.240
non-player character, how does
it know where something else is?

00:01:26.240 --> 00:01:27.840
Or maybe when it hits a wall.

00:01:27.840 --> 00:01:29.100
So talk about that technique.

00:01:29.100 --> 00:01:30.840
And then we're gonna talk
look at joints in your leaf.

00:01:30.840 --> 00:01:33.620
For example, spring joints and
hinges, how do they operate.

00:01:34.620 --> 00:01:36.550
Finally, we're gonna
talk about effectors.

00:01:36.550 --> 00:01:39.310
Things that you can apply to
various 2D objects to get some

00:01:39.310 --> 00:01:41.700
pretty cool effects
like buoyancy or

00:01:41.700 --> 00:01:43.630
to act like a conveyor belt.

00:01:44.710 --> 00:01:47.370
A kinematic rigidbody is
a bit of strange beast to

00:01:47.370 --> 00:01:48.740
wrap your head around.

00:01:48.740 --> 00:01:53.250
We look in the prior version,
in other words, our intro one

00:01:53.250 --> 00:01:56.840
on how we can use a rigidbody
component, that's added

00:01:56.840 --> 00:02:00.850
to an object to give it mass
under the influence of gravity.

00:02:00.850 --> 00:02:04.100
Now, we go the reverse route,
to disable an object,

00:02:04.100 --> 00:02:06.250
in other words,
if you wanna disable physics.

00:02:06.250 --> 00:02:08.782
Well, that's kind of strange,
wouldn't you just remove

00:02:08.782 --> 00:02:12.228
the rigidbody component
to disable it?

00:02:12.228 --> 00:02:14.920
Yes, but let's talk about a
little bit of history now before

00:02:14.920 --> 00:02:16.426
we even dive further.

00:02:16.426 --> 00:02:21.350
In Unity 4, having an object
with just a collider on it

00:02:21.350 --> 00:02:24.760
that didn't have a rigidbody was
considered a static collider.

00:02:24.760 --> 00:02:27.700
And in Unity's optimization mesh
that it built behind the scenes,

00:02:27.700 --> 00:02:30.410
it basically assumed that that
object was not going to move.

00:02:31.660 --> 00:02:32.850
And it's called
a static collider.

00:02:32.850 --> 00:02:35.660
And so if you move that object,
it really had to

00:02:35.660 --> 00:02:38.890
recalculate at runtime, these
optimizations behind the scenes,

00:02:38.890 --> 00:02:40.680
and it really hurt performance.

00:02:40.680 --> 00:02:43.250
In Unity 5,
that's no longer the case.

00:02:43.250 --> 00:02:46.600
But there still are uses to
have a kinematic rigidbody.

00:02:46.600 --> 00:02:48.453
So first,
what is a kinematic rigidbody?

00:02:50.592 --> 00:02:53.916
If we go over here to Unity,
notice we have our rigidbody

00:02:53.916 --> 00:02:57.360
component and
it's checked off is kinematic.

00:02:57.360 --> 00:02:58.140
That's it.

00:02:58.140 --> 00:03:00.410
That's a kinematic rigidbody.

00:03:00.410 --> 00:03:04.080
So, why don't we just disable
a rigidbody component?

00:03:04.080 --> 00:03:06.080
Notice, there's no checkbox
here where we have for

00:03:06.080 --> 00:03:07.378
other components.

00:03:07.378 --> 00:03:10.460
So, the physics system is kinda
special here because it is

00:03:10.460 --> 00:03:11.980
an add on system
inside of Unity,

00:03:11.980 --> 00:03:13.568
in other words
a third-party system.

00:03:13.568 --> 00:03:18.014
It's using either box2d for 2D
physics or in videos physics or

00:03:18.014 --> 00:03:19.540
3D physics.

00:03:19.540 --> 00:03:21.480
So notice, you don't have
a checkbox here to disable it.

00:03:21.480 --> 00:03:25.690
So this really is essentially
almost the same as disabling it.

00:03:25.690 --> 00:03:28.990
However, it doesn't fully
disable physics for that object.

00:03:28.990 --> 00:03:30.640
In other words,
if it has a collider,

00:03:30.640 --> 00:03:33.220
it can still participate
in a collision.

00:03:33.220 --> 00:03:35.174
Now let's go back and look at
our settings a little bit here.

00:03:35.174 --> 00:03:40.470
Used for partially disabling
physics, right there.

00:03:40.470 --> 00:03:42.276
First point,
in other words don't move me.

00:03:42.276 --> 00:03:44.890
In other words,
don't let physics move me.

00:03:44.890 --> 00:03:46.820
Now why would we do
something like this?

00:03:46.820 --> 00:03:49.600
One option is we need physics at
some point time in the future,

00:03:49.600 --> 00:03:50.880
just not right now.

00:03:50.880 --> 00:03:51.452
And that could be a ragdoll.

00:03:51.452 --> 00:03:54.327
A ragdoll is, imagine
a character walking around,

00:03:54.327 --> 00:03:57.661
and there are no physics that's
controlled by the animation

00:03:57.661 --> 00:03:59.560
system, for example.

00:03:59.560 --> 00:04:01.020
But then that character,
something happens,

00:04:01.020 --> 00:04:02.050
the character dies and

00:04:02.050 --> 00:04:04.850
it should just fall to
the ground like a ragdoll.

00:04:04.850 --> 00:04:07.000
Well, at that moment,
when the character dies,

00:04:07.000 --> 00:04:10.200
you enable physics and
then you let the colliders and

00:04:10.200 --> 00:04:11.920
the mass and
the rigidbody take over and

00:04:11.920 --> 00:04:15.030
it drops that object to
the ground, just like a ragdoll

00:04:15.030 --> 00:04:16.542
would be when you think
about a doll that you drop.

00:04:17.570 --> 00:04:20.050
Also platforms that
will act as a base for

00:04:20.050 --> 00:04:21.600
maybe other joints
like a hinge base,

00:04:21.600 --> 00:04:25.180
a floating platform that has
a swinging ball attached to it.

00:04:25.180 --> 00:04:27.220
That's a kinematic rigidbody.

00:04:27.220 --> 00:04:28.070
Physics are disabled for

00:04:28.070 --> 00:04:31.180
that platform but it basically
still understands this object is

00:04:31.180 --> 00:04:34.820
meant to participate with other
physics objects to an extent.

00:04:36.070 --> 00:04:38.040
Falling weapons can be used.

00:04:38.040 --> 00:04:41.260
Now other objects can
still collide with

00:04:41.260 --> 00:04:43.010
kinematic rigidbodies.

00:04:43.010 --> 00:04:44.490
However, there is
kind of a gotcha and

00:04:44.490 --> 00:04:45.570
we'll talk about that
that in one second.

00:04:45.570 --> 00:04:47.260
But first, NavMesh.

00:04:47.260 --> 00:04:48.980
This is Unity's
navigation system.

00:04:48.980 --> 00:04:51.340
In other words, the path finding
system built into Unity.

00:04:52.430 --> 00:04:56.080
If you have a rigidbody
that's enabled and

00:04:56.080 --> 00:04:58.240
pathfinding is turned on,
in other words,

00:04:58.240 --> 00:05:01.090
NavMesh, it's going to
fight with that object.

00:05:01.090 --> 00:05:03.271
You're gonna get really strange
behavior because the physics

00:05:03.271 --> 00:05:04.505
system's trying to
do one thing and

00:05:04.505 --> 00:05:07.030
then the navigation system
is trying to do another.

00:05:07.030 --> 00:05:08.500
But you still wanna
basically say,

00:05:08.500 --> 00:05:10.915
hey this object should really
participate in collisions.

00:05:10.915 --> 00:05:16.200
Now think about a collider,
if we go back to Unity again.

00:05:16.200 --> 00:05:20.610
If we have this object here and
it has a collider on there but

00:05:20.610 --> 00:05:21.460
it's not moving,

00:05:22.800 --> 00:05:26.120
that's usually not a concern cuz
we don't have to detect physics

00:05:26.120 --> 00:05:29.100
anywhere except where that
object currently sits.

00:05:29.100 --> 00:05:32.020
But now when you start
dragging an object around.

00:05:32.020 --> 00:05:34.990
Now we have a whole different
set of concerns, considerations

00:05:34.990 --> 00:05:37.180
cuz we have to detect when
it hits another object.

00:05:38.230 --> 00:05:40.693
And so that's where this
rigidbody comes into play,

00:05:40.693 --> 00:05:42.210
a kinematic rigidbody.

00:05:42.210 --> 00:05:43.270
We're basically saying,
all right,

00:05:43.270 --> 00:05:46.670
we still need to detect these
collisions for a moving object

00:05:46.670 --> 00:05:49.599
that is not under the influence
of the regular gravity forces.

00:05:50.680 --> 00:05:54.152
I'll show you another example
of that live in a second.

00:05:54.152 --> 00:05:56.060
But NavMesh is one of them
where you're saying hey,

00:05:56.060 --> 00:05:58.400
navigation system,
move my character.

00:05:58.400 --> 00:06:02.115
But I don't want regular
physics to effect this object.

00:06:02.115 --> 00:06:03.590
You're in charge of
moving my character.

00:06:05.040 --> 00:06:10.070
Next, collision events
are still sent as long as one

00:06:10.070 --> 00:06:15.240
of the objects involved has
a non-kinematic rigidbody.

00:06:15.240 --> 00:06:18.770
In other words, whatever object
has a kinematic rigidbody,

00:06:18.770 --> 00:06:21.350
assume it doesn't have
a rigidbody because collision

00:06:21.350 --> 00:06:26.150
events will not happen if two of
the objects have a collider and

00:06:26.150 --> 00:06:27.940
one of them has
a kinematic rigidbody.

00:06:29.370 --> 00:06:32.380
Just like we talked about
in the intro number one,

00:06:32.380 --> 00:06:35.020
one of the objects
involved in the collision

00:06:35.020 --> 00:06:36.980
must have a rigidbody component.

00:06:36.980 --> 00:06:38.010
And that holds true here,
as well.

00:06:40.110 --> 00:06:41.900
Now, moving
a kinematic rigidbody

00:06:41.900 --> 00:06:42.670
is something different.

00:06:42.670 --> 00:06:46.720
Because we are not allowing
gravity for example,

00:06:46.720 --> 00:06:48.500
to move this object for us.

00:06:48.500 --> 00:06:49.600
So there's two ways.

00:06:49.600 --> 00:06:52.460
One, is you just take
transform.position and

00:06:52.460 --> 00:06:54.210
you set that object
to a new position.

00:06:54.210 --> 00:06:55.720
That teleports it.

00:06:55.720 --> 00:06:59.170
It does not detect any physics
collisions along the way.

00:06:59.170 --> 00:07:00.440
You're basically saying,

00:07:00.440 --> 00:07:05.000
I'm here at .000 and
now I'm going to .10,10,10.

00:07:05.000 --> 00:07:08.280
There is no collisions that
happen along the way, but

00:07:08.280 --> 00:07:09.125
what if you need that?

00:07:09.125 --> 00:07:10.825
What if it's a moving
platform that

00:07:10.825 --> 00:07:12.740
you're slowing dragging back and
forth?

00:07:12.740 --> 00:07:15.000
And you have a platformer and
you have this moving platform,

00:07:15.000 --> 00:07:16.870
that's a really good
use case for this.

00:07:16.870 --> 00:07:18.260
Imagine a 3D platformer and

00:07:18.260 --> 00:07:20.378
this platform is moving back and
forth.

00:07:20.378 --> 00:07:22.780
We'll use
rigidbody.MovePosition and

00:07:22.780 --> 00:07:26.180
it basically takes that
kinematic rigidbody and

00:07:26.180 --> 00:07:29.270
drags it, so it will detect
collisions along the way.

00:07:30.760 --> 00:07:31.780
A kinematic rigidbody,

00:07:31.780 --> 00:07:33.650
this is another very
important point here,

00:07:33.650 --> 00:07:36.840
it can push another object but
a kinematic rigidbody

00:07:36.840 --> 00:07:39.180
can't be pushed by
another falling object.

00:07:39.180 --> 00:07:41.300
So it's another
special case here.

00:07:41.300 --> 00:07:42.910
It's a great use for
a platform, right?

00:07:42.910 --> 00:07:45.169
You have a platform moving
along in your 3D platformer and

00:07:45.169 --> 00:07:46.137
it hits another object,

00:07:46.137 --> 00:07:48.086
it's gonna push that object
right out of the way.

00:07:48.086 --> 00:07:51.908
But that falling object onto
that platform will not change

00:07:51.908 --> 00:07:53.750
that platform's path.

00:07:53.750 --> 00:07:54.750
It won't act like it's been hit.

00:07:56.690 --> 00:07:59.830
Let's go ahead and look at some
demos of kinematic rigidbodies.

00:08:01.370 --> 00:08:04.400
Here we are in my kinematic
test scene inside of Unity.

00:08:04.400 --> 00:08:06.020
Now, this looks pretty basic and
it is,

00:08:06.020 --> 00:08:08.020
it's a nice simple demo case.

00:08:08.020 --> 00:08:08.880
Let's run this,

00:08:08.880 --> 00:08:11.750
and you will see that we just
have a couple of objects falling

00:08:11.750 --> 00:08:14.899
down on a particular plane here,
on this side.

00:08:16.070 --> 00:08:17.710
And this guy that's
moving across.

00:08:19.000 --> 00:08:21.550
So think of this as a moving
platform that you need to move

00:08:21.550 --> 00:08:22.380
in code.

00:08:22.380 --> 00:08:25.850
We're not allowing physics
to move this object,

00:08:25.850 --> 00:08:28.150
we are specifically
moving this object.

00:08:28.150 --> 00:08:30.280
It's a great case for
a platform in a game.

00:08:30.280 --> 00:08:34.350
And this object here,
this pillar one has a rigidbody.

00:08:35.370 --> 00:08:38.550
It has a light mass,
it's mass of only 1.

00:08:38.550 --> 00:08:40.580
And it is currently kinematic.

00:08:42.220 --> 00:08:44.130
This is gonna go and
push the other object.

00:08:44.130 --> 00:08:47.520
If I pause this and then frame
advance, we can see that

00:08:48.860 --> 00:08:51.440
as we go forward,
we'll eventually come over here,

00:08:51.440 --> 00:08:54.600
catch up, and then push this
other object out of the way.

00:08:54.600 --> 00:08:59.040
So even though this is
a kinematic rigidbody,

00:08:59.040 --> 00:09:02.830
this will still actually
participate in physics here.

00:09:02.830 --> 00:09:05.760
And if you think, well,
technically, can't you just

00:09:05.760 --> 00:09:07.400
do this with a regular
object without a rigidbody?

00:09:07.400 --> 00:09:09.910
You can but
you get a different reaction.

00:09:09.910 --> 00:09:11.910
So notice, as soon as we touch
that object, we're pushing it.

00:09:13.520 --> 00:09:15.580
Let's try a couple
different scenarios here.

00:09:15.580 --> 00:09:19.940
Lets go over to the code and
notice that right now,

00:09:19.940 --> 00:09:22.800
we're using
_rigidBody.MovePosition.

00:09:22.800 --> 00:09:24.765
So in other words,
when this code starts up,

00:09:24.765 --> 00:09:27.148
I'm getting a reference to
the rigidbody component,

00:09:27.148 --> 00:09:28.824
pretty standard
operation in Unity.

00:09:28.824 --> 00:09:31.333
And then here in fixedUpdate,

00:09:31.333 --> 00:09:37.134
which I explained in the first
module, _rigidBody.MovePosition.

00:09:37.134 --> 00:09:39.853
We're taking the current
position and transform.forward,

00:09:39.853 --> 00:09:41.954
which is simply a vector
of (0,0,1), and

00:09:41.954 --> 00:09:43.593
we're multiplying
it by some speed,

00:09:43.593 --> 00:09:46.480
which in this case is 1 which
means essentially no change.

00:09:46.480 --> 00:09:48.470
We're gonna change this
in a little bit though.

00:09:48.470 --> 00:09:49.989
Times Time.deltaTime,

00:09:49.989 --> 00:09:52.960
the amount of time the last
frame took to complete.

00:09:52.960 --> 00:09:56.212
Now FixedUpdate() runs
every 50 frames a second.

00:09:56.212 --> 00:09:59.534
So 0.02 times a second and
you can change that.

00:09:59.534 --> 00:10:02.758
So if your physics simulations
are not running with enough

00:10:02.758 --> 00:10:04.675
accuracy you can
try to increase.

00:10:04.675 --> 00:10:08.917
Your fixed time step that we
looked at in the last module.

00:10:08.917 --> 00:10:12.286
So, right now, i'm using move
position, this essentially drags

00:10:12.286 --> 00:10:14.660
the rigid body along and
causes the collision.

00:10:14.660 --> 00:10:18.170
Let's greatly increase
this time here to 50, so

00:10:18.170 --> 00:10:20.950
I have code that's
moving this rigid body.

00:10:20.950 --> 00:10:22.320
Let's see what it looks like,
actually,

00:10:22.320 --> 00:10:26.495
first let's go the other route,
let's look at using transform,

00:10:26.495 --> 00:10:30.420
position to, quote,
teleport our object, and

00:10:30.420 --> 00:10:31.190
let's see what happens now.

00:10:31.190 --> 00:10:36.560
Let's save that,
connect Unity, pause, play, and

00:10:36.560 --> 00:10:40.170
notice that as we frame advance
here, we're starting at 0.05.

00:10:40.170 --> 00:10:43.675
Actually, we're technically
starting at negative

00:10:43.675 --> 00:10:48.300
0.05 on the z, so every frame
we're going one meter, and

00:10:48.300 --> 00:10:51.850
notice where the boxes here, so

00:10:51.850 --> 00:10:53.410
we're kind of in
the center right there.

00:10:55.100 --> 00:11:00.510
Now each frame that we advance,
right there and right there.

00:11:00.510 --> 00:11:02.170
Now notice how this looks,

00:11:03.420 --> 00:11:06.490
our collider is kinda pushed
down this object a little bit,

00:11:06.490 --> 00:11:09.960
and once we go by this object
kinda presses back up again.

00:11:09.960 --> 00:11:12.950
So, we get this weird behavior
that happens on an object

00:11:12.950 --> 00:11:14.700
when we're simply
teleporting our object.

00:11:14.700 --> 00:11:16.900
We're not using physics, so

00:11:16.900 --> 00:11:20.480
let's go back and use
the rigidBody.MovePosition, and,

00:11:20.480 --> 00:11:22.580
remember, we have
a kinematic rigid body here.

00:11:24.910 --> 00:11:26.859
Pause, Play, and Frame Advance.

00:11:29.240 --> 00:11:31.350
Okay, first frame
we're up one meter.

00:11:32.730 --> 00:11:33.730
Now we're one more meter,

00:11:33.730 --> 00:11:36.840
now notice we do get this kind
of silly little press in here,

00:11:38.090 --> 00:11:39.340
but the very next frame, boom,

00:11:39.340 --> 00:11:43.480
we've pushed that object out of
the way, so that works better.

00:11:45.560 --> 00:11:46.310
So, hopefully,

00:11:46.310 --> 00:11:48.840
you can see kind of the use
of this kinematic rigid body.

00:11:48.840 --> 00:11:52.340
You're gonna move something
in code or not at all, but

00:11:52.340 --> 00:11:53.880
you still,
at some point in time,

00:11:53.880 --> 00:11:56.800
will need this to somehow
act like a physics object.

00:11:59.420 --> 00:12:03.400
If we go ahead and change
some other settings on this,

00:12:03.400 --> 00:12:06.710
we can see where Properties or
a rigid body can help us out.

00:12:06.710 --> 00:12:08.910
So for example, interpolate,

00:12:08.910 --> 00:12:11.440
we'll talk about collision
detection in a little bit, but

00:12:11.440 --> 00:12:14.710
interpolate, we have none,
interpolate, and extrapolate.

00:12:16.380 --> 00:12:19.090
Notice that when we
were doing our code of

00:12:19.090 --> 00:12:20.210
rigid body move position.

00:12:21.730 --> 00:12:23.760
We still get a little
bit of oddity here.

00:12:23.760 --> 00:12:25.220
Let's go ahead and
pause this again,

00:12:25.220 --> 00:12:29.170
play, frame one, frame two.

00:12:29.170 --> 00:12:32.280
Well, lets see what happens

00:12:32.280 --> 00:12:36.330
if we change this interpolate
mode to interpolate, and

00:12:36.330 --> 00:12:41.025
what this will do is this will
help out certain scenarios where

00:12:41.025 --> 00:12:45.680
our physics timestep, In other
words our 50 frames a second.

00:12:47.070 --> 00:12:47.670
This guy right here,

00:12:47.670 --> 00:12:50.820
our fixed update Is out of
sync with our update call.

00:12:50.820 --> 00:12:53.780
We don't actually have an update
here but this update object

00:12:53.780 --> 00:12:55.170
behind the scenes was
still doing the update,

00:12:55.170 --> 00:12:56.250
it's getting drawn.

00:12:58.510 --> 00:13:00.430
You can actually,
to make this correct fix update,

00:13:00.430 --> 00:13:04.150
it's called 50 times
a second by default.

00:13:05.270 --> 00:13:10.820
It goes point 02 of a second,
with that last module All right.

00:13:10.820 --> 00:13:13.870
Now, because update and
fix update run at different

00:13:13.870 --> 00:13:17.060
intervals, we can get a scenario
where we're drawing an object

00:13:17.060 --> 00:13:20.510
one way and, maybe the physics
hasn't caught up or vice versa.

00:13:20.510 --> 00:13:22.060
Depending on when our
physics frame runs,

00:13:22.060 --> 00:13:24.910
our object might be physically
in a different position than

00:13:24.910 --> 00:13:27.910
we're drawing it,
according to the physics engine.

00:13:27.910 --> 00:13:30.460
So interpolate will help
try to predict this,

00:13:30.460 --> 00:13:32.410
where your object should be.

00:13:32.410 --> 00:13:34.070
Typically use this on a player,

00:13:34.070 --> 00:13:37.440
to make the player look
more consistent and

00:13:37.440 --> 00:13:40.990
not get this stuttery movement,
or jaggedy movement.

00:13:40.990 --> 00:13:43.290
So let's go ahead and
try this, play.

00:13:45.810 --> 00:13:51.655
And Our first frame,
notice right away,

00:13:51.655 --> 00:13:55.520
we're drawing here.

00:13:55.520 --> 00:13:58.328
But notice how our object seems
to be right there based on

00:13:58.328 --> 00:13:59.238
this transform.

00:14:02.168 --> 00:14:03.440
Okay, we're going forward.

00:14:03.440 --> 00:14:03.940
Notice again.

00:14:06.088 --> 00:14:06.588
Boom.

00:14:08.170 --> 00:14:13.450
So we get this reactionary
counter measure,

00:14:13.450 --> 00:14:16.680
so to say, wheer we are actually
pushing this object

00:14:16.680 --> 00:14:22.070
ahead of time, to try to make
sure tha we don't get this

00:14:22.070 --> 00:14:24.380
object buried in
the other object.

00:14:24.380 --> 00:14:25.070
The other mode here,

00:14:25.070 --> 00:14:29.580
extrapolate, will also try
to predict But you can

00:14:29.580 --> 00:14:32.470
actually have an instance where
extrapolate can overshoot.

00:14:32.470 --> 00:14:35.920
So the interpolate was kinda
being more cautious about it.

00:14:35.920 --> 00:14:38.490
Extrapolate can actually
overshoot, and in some cases,

00:14:38.490 --> 00:14:41.340
if you're stopping at
the border of an object,

00:14:41.340 --> 00:14:43.620
it can actually display
it past it one frame, and

00:14:43.620 --> 00:14:45.440
then come back the next frame.

00:14:45.440 --> 00:14:47.350
We won't see that here in
this particular demo, but

00:14:47.350 --> 00:14:48.570
just to tell you
that can happen.

00:14:49.870 --> 00:14:52.150
We will see what does look like
incorrect behavior though.

00:14:52.150 --> 00:14:55.190
If we go forward,
forward, there we go.

00:14:55.190 --> 00:14:58.920
So our 0.5, again,
was shot into the object.

00:14:58.920 --> 00:15:02.260
So, you have to choose
which case looks the best.

00:15:02.260 --> 00:15:04.350
Usually, again, you use these
settings on the player.

00:15:05.740 --> 00:15:08.740
These are just some demo
objects I'm showing you here.

00:15:08.740 --> 00:15:10.954
But in this particular case
I would probably opt for

00:15:10.954 --> 00:15:12.146
the route of interpolate.

00:15:15.608 --> 00:15:17.210
All right, so let me save this.

00:15:18.910 --> 00:15:21.320
Let's talk about what we
covered real quick here.

00:15:21.320 --> 00:15:25.410
In fixedUpdate we're
moving our actual

00:15:26.910 --> 00:15:28.510
Kinematic rigidbody
by two methods,

00:15:28.510 --> 00:15:31.860
either transform.position, which
is a teleporting method, or

00:15:31.860 --> 00:15:33.870
we're moving it by
_rigidBody.MovePosition,

00:15:33.870 --> 00:15:38.240
which really drags it through a
position from point a to point b

00:15:38.240 --> 00:15:39.930
and we can get collisions
along the way.

00:15:41.220 --> 00:15:44.990
So we covered two topics there,
And kinematic rigidbodies.

00:15:44.990 --> 00:15:47.500
So hopefully, that makes
a little bit more sense.

00:15:47.500 --> 00:15:52.770
What we're gonna look at in
the future are actual rag dolls,

00:15:52.770 --> 00:15:54.220
another instance of a rigidbody.

00:15:54.220 --> 00:15:57.040
But since we're talking
about kinematic rigidbodies,

00:15:57.040 --> 00:16:00.570
I should say, just to show
you what happens when you

00:16:00.570 --> 00:16:03.360
have an object with
a kinematic rigidbody, And

00:16:03.360 --> 00:16:06.010
then you suddenly turn
into a real rigid body.

00:16:06.010 --> 00:16:10.030
All right, so we're gonna talk
about ragdolls in just a little

00:16:10.030 --> 00:16:11.370
bit, but I wanna show you
something cool ahead of time.

00:16:13.710 --> 00:16:16.600
Collision detection modes is
an area of your rigid body which

00:16:16.600 --> 00:16:19.200
defines how your
object will react

00:16:19.200 --> 00:16:21.420
in various speed collisions.

00:16:21.420 --> 00:16:22.690
Now, out of the box,
is Discrete.

00:16:22.690 --> 00:16:25.420
And that's your typical uses,
your default.

00:16:25.420 --> 00:16:29.330
And that holds true and
good for many basic cases.

00:16:29.330 --> 00:16:32.840
A ball is rolling along a hill,
or two things collide into each

00:16:32.840 --> 00:16:36.640
other at an okay speed,
this works just fine.

00:16:36.640 --> 00:16:38.490
Things start to get
a little bit goofy when you

00:16:38.490 --> 00:16:40.340
start going faster.

00:16:40.340 --> 00:16:43.810
If you have a fast moving object
you can actually give it a case,

00:16:43.810 --> 00:16:45.880
and i'll show you this in the
demo, where you teleport through

00:16:45.880 --> 00:16:47.900
another object even though
you're using a collider and

00:16:47.900 --> 00:16:49.330
you're using a rigid-body.

00:16:49.330 --> 00:16:51.610
You can still get teleportation
that happens, in other words you

00:16:51.610 --> 00:16:54.860
skip right through an object
rather than hitting an object.

00:16:54.860 --> 00:16:57.860
Again this is really only
used for fast moving objects.

00:16:57.860 --> 00:17:00.070
And there are other ways
to help mitigate this.

00:17:00.070 --> 00:17:02.680
In other words, make sure that
your fixed time set is faster.

00:17:02.680 --> 00:17:04.630
You have faster physic steps.

00:17:04.630 --> 00:17:07.010
But another way of doing this
is by using a physics system to

00:17:07.010 --> 00:17:08.840
change your collision
detection mode.

00:17:08.840 --> 00:17:11.520
So there's continuous and
then continuous dynamic and

00:17:11.520 --> 00:17:13.460
that's used when both
objects are moving and

00:17:13.460 --> 00:17:14.910
one of them is continuous.

00:17:14.910 --> 00:17:16.710
Set in on
the continuous dynamic.

00:17:16.710 --> 00:17:17.790
And I'll demo this in a second.

00:17:17.790 --> 00:17:18.750
This gonna be very clear.

00:17:18.750 --> 00:17:23.090
You'll really easy to see what's
happening I commented on a forum

00:17:23.090 --> 00:17:27.720
on Unity's website where I
posted some of my findings here.

00:17:27.720 --> 00:17:29.320
So I'll show you
that in a second.

00:17:29.320 --> 00:17:31.030
But first let's go and
look at a DEMO inside Unity.

00:17:31.030 --> 00:17:34.990
Let me first explain what's
gonna in this scene.

00:17:34.990 --> 00:17:38.730
We have a hanging hinge
joint connected to

00:17:38.730 --> 00:17:43.420
a Note here this is
a kinematic rigibody.

00:17:43.420 --> 00:17:44.950
So it's a hanging platform.

00:17:44.950 --> 00:17:46.820
I'll talk about why in a little
bit why you need that for

00:17:46.820 --> 00:17:48.220
a hinge joint when we
talk about joints.

00:17:49.220 --> 00:17:50.380
But now I have this wall.

00:17:50.380 --> 00:17:52.570
I have a shooter game object.

00:17:52.570 --> 00:17:55.830
It does nothing than take this
projectile, instantiate it, and

00:17:55.830 --> 00:17:57.319
give it a velocity and
shoot it out.

00:17:58.560 --> 00:18:00.810
It's collision detection mode,
it's default here,

00:18:00.810 --> 00:18:01.410
it's discreet.

00:18:02.430 --> 00:18:04.890
Our little hanging ball here,

00:18:04.890 --> 00:18:07.340
the collision detection mode
there is discreet as well.

00:18:07.340 --> 00:18:08.170
Default out of the box.

00:18:09.520 --> 00:18:12.410
Notice when I play and
I click the mouse button here,

00:18:13.910 --> 00:18:15.784
let's go ahead and
enter a speed of 40.

00:18:17.360 --> 00:18:22.710
So I hit that and I bounce off
the wall as well, pretty basic.

00:18:22.710 --> 00:18:24.170
If I go to 49, for example, 49.

00:18:24.170 --> 00:18:27.180
Same thing I'm hitting the wall.

00:18:27.180 --> 00:18:29.490
Let me go to 50 meters a second.

00:18:30.730 --> 00:18:31.670
I'm going right
through the wall.

00:18:33.690 --> 00:18:34.250
That's a problem.

00:18:35.440 --> 00:18:40.370
Now what about if I have
Say 200 meters a second.

00:18:42.850 --> 00:18:44.960
So I hit the hanging ball, but

00:18:44.960 --> 00:18:47.880
on the flip side it went right
through the back wall there.

00:18:47.880 --> 00:18:49.800
So maybe if I change this
to 400 meters a second,

00:18:49.800 --> 00:18:52.970
no I'll still hit that one too.

00:18:52.970 --> 00:18:54.180
If we try this enough times,

00:18:54.180 --> 00:18:55.600
we'll eventually
find a case where.

00:18:57.710 --> 00:18:58.740
There we go.

00:18:58.740 --> 00:19:01.090
See, we're shooting right
through both objects here,

00:19:01.090 --> 00:19:03.100
and we're not catching
those collisions.

00:19:04.650 --> 00:19:07.170
So this is where changing our
collision detection mode can be

00:19:07.170 --> 00:19:08.870
advantageous to us.

00:19:08.870 --> 00:19:13.130
If we change our collision
detection to continuous, and

00:19:13.130 --> 00:19:13.899
now we run this,

00:19:14.980 --> 00:19:17.280
Against our static collider
object here in the back.

00:19:18.490 --> 00:19:21.100
This wall that's in the back
is nothing more than an object

00:19:21.100 --> 00:19:22.360
that has a boxglider.

00:19:25.020 --> 00:19:26.740
So at 100 meters a second,

00:19:26.740 --> 00:19:28.700
notice I'm no longer going
through that wall, right?

00:19:28.700 --> 00:19:31.180
Our point before was
50 meters a second.

00:19:31.180 --> 00:19:32.378
I'm going faster than that.

00:19:32.378 --> 00:19:34.180
Let's try 400.

00:19:34.180 --> 00:19:34.870
Even at 400, boom.

00:19:34.870 --> 00:19:37.430
I hit that and I stop.

00:19:37.430 --> 00:19:38.560
That'd be 500.

00:19:38.560 --> 00:19:41.870
Even at 500 it hits
that wall and stops.

00:19:41.870 --> 00:19:44.700
Now there is an impact on
performance for doing that.

00:19:44.700 --> 00:19:47.160
So use it wisely when you know
you're gonna have a problem.

00:19:49.000 --> 00:19:50.240
Let's go ahead and
try 500 now here.

00:19:50.240 --> 00:19:53.362
Okay, so
I'm hitting the wall, but

00:19:53.362 --> 00:19:58.319
notice I'm still flying
through This ball, right here.

00:19:58.319 --> 00:20:03.269
So that ball is currently
set to discrete.

00:20:03.269 --> 00:20:06.102
If I make that ball
continuous and run, and

00:20:06.102 --> 00:20:08.227
let me set my default to 500,

00:20:08.227 --> 00:20:11.790
notice it's still going
right through that object.

00:20:13.130 --> 00:20:16.555
So this is a case where I need
to make the ball continuous

00:20:16.555 --> 00:20:17.231
dynamic.

00:20:22.398 --> 00:20:25.096
Now, I'm gonna choose to
make the ball continuous

00:20:25.096 --> 00:20:28.340
dynamic because there are less
of them in the scene.

00:20:28.340 --> 00:20:33.480
In theory, I could make
my actual projectile

00:20:33.480 --> 00:20:35.930
continuous dynamic but I'm
making a lot of those the scene.

00:20:35.930 --> 00:20:37.920
So to me from a performance
standpoint it makes

00:20:37.920 --> 00:20:40.069
sense to do it to as few
objects as possible.

00:20:41.320 --> 00:20:44.281
So I'm gonna do it
just to this ball,

00:20:44.281 --> 00:20:48.310
change this back to 500,
and try that.

00:20:48.310 --> 00:20:48.810
Boom.

00:20:50.060 --> 00:20:51.080
So, that'll work every time.

00:20:52.770 --> 00:20:55.220
Pretty basic demo,
easy to set up.

00:20:55.220 --> 00:20:57.580
Again, you wanna change away
from defaults when you notice

00:20:57.580 --> 00:20:59.420
that there's an issue or
you know there might

00:20:59.420 --> 00:21:01.421
be an issue when you have
a fast moving projectile.

00:21:03.220 --> 00:21:04.920
Now, if you're brand new
to game development,

00:21:04.920 --> 00:21:06.430
you might think, okay, great.

00:21:06.430 --> 00:21:10.200
I've got a bullet and a bullet
is gonna shoot really fast.

00:21:10.200 --> 00:21:11.510
So I need this for a bullet.

00:21:11.510 --> 00:21:14.230
And that's usually not the case
because bullets are usually not

00:21:14.230 --> 00:21:15.275
real projectiles.

00:21:15.275 --> 00:21:18.210
[LAUGH] It's only a visual
effect, and then you actually do

00:21:18.210 --> 00:21:21.830
a Raycast, which will tell
us if we've hit something.

00:21:21.830 --> 00:21:24.266
So this may be a good time to
start talking about Raycast.

00:21:28.228 --> 00:21:30.987
I don't know how else to say
it because [LAUGH] Raycasting

00:21:30.987 --> 00:21:31.970
is awesome.

00:21:31.970 --> 00:21:33.100
This is a really neat technique,
and

00:21:33.100 --> 00:21:35.320
you'll see this across
many different games,

00:21:35.320 --> 00:21:38.550
whether you're running on
your phone or your console.

00:21:38.550 --> 00:21:41.380
Raycasting shoots
an invisible arrow out,

00:21:41.380 --> 00:21:44.700
in other words a ray,
it casts out a ray.

00:21:44.700 --> 00:21:46.300
So think of it like
an invisible arrow and

00:21:46.300 --> 00:21:48.520
you're basically wondering
what it's gonna hit.

00:21:48.520 --> 00:21:50.726
This works for 2D and 3D.

00:21:50.726 --> 00:21:53.889
And you can say, tell me
the first object I hit by

00:21:53.889 --> 00:21:57.530
Physics.Raycast or you can
ask for all objects at this

00:21:57.530 --> 00:22:00.980
particular ray has hit
via Physics.RaycastAll.

00:22:00.980 --> 00:22:03.740
And when you cast out a ray,
you can specify a distance.

00:22:03.740 --> 00:22:06.920
For example,
you can Raycast out 50 meters.

00:22:06.920 --> 00:22:09.590
You could also limit the layers
that you're searching on.

00:22:09.590 --> 00:22:12.930
You can put objects on
different layers and

00:22:12.930 --> 00:22:14.960
only Raycast against
those layers.

00:22:14.960 --> 00:22:19.700
So for example, if you have
a bunch of industrial buildings,

00:22:19.700 --> 00:22:22.460
homes, buildings,
on a particular layer,

00:22:22.460 --> 00:22:23.700
but you're really looking for

00:22:23.700 --> 00:22:27.680
zombies, you don't wanna include
those buildings in your Raycast

00:22:27.680 --> 00:22:30.280
checks because they just gonna
discard those results anyway.

00:22:30.280 --> 00:22:32.250
So you can basically put all of
your zombies on a particular

00:22:32.250 --> 00:22:34.660
layer and
only Raycast against that layer.

00:22:34.660 --> 00:22:36.266
I'll show you
a quick momentarily.

00:22:37.600 --> 00:22:40.890
Now, the thing is the objects
that you are Raycasting against

00:22:40.890 --> 00:22:43.470
to be notified,
must have a collider on them.

00:22:43.470 --> 00:22:47.110
Triggers also work, but you need
to specify that you want to

00:22:47.110 --> 00:22:50.340
query trigger interaction,
when you make your API call, or

00:22:50.340 --> 00:22:51.970
you can search for
them globally.

00:22:51.970 --> 00:22:52.540
In other words,

00:22:52.540 --> 00:22:56.428
you can set this value,
physics.queriesHitTriggers.

00:22:56.428 --> 00:23:00.150
Set that equals to true and
then any of your Physics.Raycast

00:23:00.150 --> 00:23:02.660
calls will actually
check triggers as well.

00:23:02.660 --> 00:23:04.270
Let's get right to
a demo because this is

00:23:04.270 --> 00:23:04.840
a cool technique.

00:23:04.840 --> 00:23:06.000
I want you to see
it right up close.

00:23:07.330 --> 00:23:10.010
In this demo, we're gonna
look at the previous demo

00:23:10.010 --> 00:23:13.880
where we used to check out
a sleeping rigid bodies.

00:23:13.880 --> 00:23:15.810
But this is also a good one
because this has some code in

00:23:15.810 --> 00:23:20.050
it where we can identify the
colliders that we're looking at.

00:23:20.050 --> 00:23:23.340
So if I run this, watch when
I move the mouse around.

00:23:23.340 --> 00:23:25.970
Any time I get over something
that has a collider on there,

00:23:25.970 --> 00:23:27.830
it highlights that object.

00:23:27.830 --> 00:23:32.000
Secondly, if I click on
an object what happens is,

00:23:32.000 --> 00:23:35.460
if I go to this view,
you'll see we've drawn a line.

00:23:35.460 --> 00:23:38.620
That line goes from my camera,
let's advance a couple frames,

00:23:38.620 --> 00:23:39.450
get those out of the way.

00:23:41.910 --> 00:23:45.290
That line goes from the camera
out to the object that I hit.

00:23:46.320 --> 00:23:48.350
Now typically, you don't see
it here because of the angle.

00:23:48.350 --> 00:23:49.770
It makes it a little
bit tough to see.

00:23:49.770 --> 00:23:54.670
Sometimes if you rotate
things around, there we go,

00:23:54.670 --> 00:23:57.540
you can see right there, coming
down on this left hand side.

00:23:59.090 --> 00:24:01.270
Now, typically when it comes
straight out from the camera,

00:24:01.270 --> 00:24:02.910
you can't see it.

00:24:02.910 --> 00:24:04.197
So changing
perspective a little,

00:24:04.197 --> 00:24:06.070
I can't, that's why I like to go
to the scene view because I can

00:24:06.070 --> 00:24:08.140
see from the side of
the camera here and

00:24:08.140 --> 00:24:10.670
see where it initially shot
out to where it pointed.

00:24:10.670 --> 00:24:13.810
So we can draw a debug line,
that's what that is.

00:24:13.810 --> 00:24:18.430
And we're also clicking on
an object to remove it.

00:24:18.430 --> 00:24:19.960
And of course,
when I click on the platform,

00:24:19.960 --> 00:24:21.030
they all go bye, bye as well.

00:24:22.320 --> 00:24:23.310
Now, let's see what
happened there.

00:24:23.310 --> 00:24:26.500
I have a Raycast hit
check game object.

00:24:26.500 --> 00:24:28.370
And that code does something
pretty basic here.

00:24:30.170 --> 00:24:34.440
Every frame here, in Update,
what we're doing is,

00:24:34.440 --> 00:24:38.520
in fact, I can just remove that,
what we're doing in this

00:24:38.520 --> 00:24:42.430
particular frame is grabbing
the input that mouse position.

00:24:42.430 --> 00:24:44.390
And actually if you're wondering
why I have these curly braces

00:24:44.390 --> 00:24:45.120
here it's because

00:24:45.120 --> 00:24:47.040
I'm just closing in the scope
of these variables.

00:24:48.110 --> 00:24:50.230
So, these are just
byte sized MOs.

00:24:50.230 --> 00:24:52.180
So anytime you enclose
in a scope like that you

00:24:52.180 --> 00:24:53.730
can reuse a name.

00:24:53.730 --> 00:24:56.450
And so, I have mouse position
here and it's also being reused

00:24:56.450 --> 00:24:58.520
down here because it's
within a separate scope.

00:25:00.634 --> 00:25:02.210
All right, so
this is mouse position, and

00:25:02.210 --> 00:25:06.740
put that mouse position and what
we're doing is taking that mouse

00:25:06.740 --> 00:25:08.100
position where I'm
on the screen,

00:25:08.100 --> 00:25:13.100
and converting it from
a screen point to a ray.

00:25:13.100 --> 00:25:15.707
So this will give
us a ray object.

00:25:15.707 --> 00:25:18.660
Now, again, that's just taking
wherever my mouse is moving on

00:25:18.660 --> 00:25:19.490
the screen here.

00:25:21.470 --> 00:25:22.452
Let me undo what I just did,
here.

00:25:29.472 --> 00:25:33.282
Let's run this, this is just
simply taking what I'm looking

00:25:33.282 --> 00:25:35.930
at here on the screen,
and creating a ray.

00:25:37.840 --> 00:25:40.700
Now, what we're also do in every
frame is we're shooting out that

00:25:40.700 --> 00:25:44.010
ray and asking for the single
object that we've hit.

00:25:44.010 --> 00:25:47.200
If we happen to have hit
an object, we're asking for

00:25:47.200 --> 00:25:49.050
it's MeshRenderer,
which is responsible for

00:25:49.050 --> 00:25:49.800
drawing that cube.

00:25:51.130 --> 00:25:54.690
If it's a moving object like
a soldier, for example, or

00:25:54.690 --> 00:25:57.430
a zombie, that would be
a SkinnedMeshRenderer.

00:25:57.430 --> 00:25:59.460
For all the other objects,
MeshRenderer.

00:25:59.460 --> 00:26:01.179
So we're asking for
the MeshRenderer and

00:26:01.179 --> 00:26:03.110
setting a property
on a called Color.

00:26:03.110 --> 00:26:03.760
We can turn it to red.

00:26:04.860 --> 00:26:09.070
So if we happen to have hit
an object, turn it red.

00:26:09.070 --> 00:26:09.570
That's it.

00:26:11.140 --> 00:26:14.050
So in practice,
it looks just like this.

00:26:14.050 --> 00:26:15.510
Every frame, we're going out

00:26:16.940 --> 00:26:20.600
seeing what we're in front
of and then coloring it red.

00:26:20.600 --> 00:26:25.950
Now, secondly, if you press
fire1, the left mouse button,

00:26:25.950 --> 00:26:29.460
grab the screen position from
the mouse, convert it to a ray.

00:26:31.570 --> 00:26:33.950
If we've hit an object,
draw a line, so

00:26:33.950 --> 00:26:38.638
debug that draw a line, Our
ray origin, so in other words,

00:26:38.638 --> 00:26:42.040
that's where we are clicking on
the screen, that's our origin

00:26:42.040 --> 00:26:45.920
and our hit point is who we just
hit, in other words, the cube.

00:26:45.920 --> 00:26:49.390
It's going to be red and stick
around for four seconds and

00:26:49.390 --> 00:26:50.030
that's it.

00:26:50.030 --> 00:26:52.980
Now, if we actually have
a game object, which

00:26:52.980 --> 00:26:56.410
we should of course, we're gonna
destroy whoever we've just hit.

00:26:57.720 --> 00:27:01.005
Now if we have custom code,
for example, maybe on that

00:27:01.005 --> 00:27:03.360
gameObject we have a script
called SoldierController and

00:27:03.360 --> 00:27:06.120
we need to get that script to
communicate with a gameObject,

00:27:06.120 --> 00:27:09.600
we can just do something like
GetComponent<SoldierController

00:27:09.600 --> 00:27:11.300
and then call whatever
code we need.

00:27:11.300 --> 00:27:18.753
For example,
.GetComponent<SoldierController.

00:27:20.958 --> 00:27:23.778
And that will give us that
SoldierController code,

00:27:23.778 --> 00:27:27.230
if that cube or enemy happen
to have that code on there.

00:27:27.230 --> 00:27:29.530
And then in turn, of course,
we can just call some function,

00:27:29.530 --> 00:27:31.790
whether it's Die or GotHit or
something like that.

00:27:31.790 --> 00:27:34.200
But in this case,
we're just using simple cubes.

00:27:34.200 --> 00:27:36.370
So we're just gonna keep
this pretty basic here and

00:27:36.370 --> 00:27:38.450
just get the gameObject
that we just hit.

00:27:39.780 --> 00:27:41.320
And of course, we saw that
when you click on something

00:27:41.320 --> 00:27:41.860
it destroys it.

00:27:44.030 --> 00:27:46.370
This here is simply
using Physics.Raycast.

00:27:46.370 --> 00:27:50.790
If you look for
Physics.RaycastAll,

00:27:50.790 --> 00:27:53.900
you'll notice that you can
get other information back.

00:27:53.900 --> 00:27:56.986
In other words, you'll get
an array of Raycast hit back.

00:27:56.986 --> 00:28:01.790
Where as Physics.Raycast simply
turns a bullion result and

00:28:01.790 --> 00:28:05.500
then you give it an out
perimeter of your actual hit.

00:28:05.500 --> 00:28:07.280
This right here the RaycastHit.

00:28:07.280 --> 00:28:09.932
RaycastAll will actually
return you in an array and

00:28:09.932 --> 00:28:13.270
then you look for that array,
so slightly different approach.

00:28:15.620 --> 00:28:17.508
There are other ways of
checking for objects,

00:28:17.508 --> 00:28:23.245
Physics.Over lap box, overlap
sphere, and this will return

00:28:23.245 --> 00:28:26.490
arrays of the colliders that
are touching within this sphere.

00:28:26.490 --> 00:28:29.332
So I simply wanna know if
something is within a one unit

00:28:29.332 --> 00:28:31.857
sphere for me, I don't
have to make a trigger or

00:28:31.857 --> 00:28:34.003
a collider net range,
I can simply say,

00:28:34.003 --> 00:28:36.846
Physics.Over laps sphere for
my current position,

00:28:36.846 --> 00:28:39.398
and give me back all
the objects that I've hit.

00:28:39.398 --> 00:28:42.232
Same thing with a box, and same
thing with non alloc versions

00:28:42.232 --> 00:28:44.957
which are more performance
enhanced versions that don't

00:28:44.957 --> 00:28:46.530
allocate extra memory for them.

00:28:47.650 --> 00:28:48.866
So a couple cool
things you can do, but

00:28:48.866 --> 00:28:49.786
Raycasting is really neat.

00:28:49.786 --> 00:28:55.520
Now, if we look over
here on GitHub.

00:28:55.520 --> 00:28:59.768
I have a project up there on
github.com/AdamChulupervampkidv-

00:28:59.768 --> 00:29:04.580
ersezombieapocolypse and
in there the zombie controller

00:29:04.580 --> 00:29:09.330
code happens to have a little
bit of logic in here.

00:29:09.330 --> 00:29:10.740
Let's scroll down to it.

00:29:10.740 --> 00:29:12.603
When it does its Raycast, now,

00:29:12.603 --> 00:29:16.264
notice a 2D physics Raycast
is called physics2d.raycast.

00:29:17.650 --> 00:29:19.075
And what the zombies
do in this game,

00:29:19.075 --> 00:29:20.900
their really stupid zombies,

00:29:20.900 --> 00:29:23.500
they just simply shoot out
an arrow to the left, and

00:29:23.500 --> 00:29:25.320
shoot out an arrow to the right,
and they look for the player.

00:29:26.910 --> 00:29:30.468
So physics Raycast for my
current position, we're gonna go

00:29:30.468 --> 00:29:33.883
out to the left, we're gonna
go an infinite range, now,

00:29:33.883 --> 00:29:37.180
I could limit this and
say 100 meters, for example.

00:29:37.180 --> 00:29:40.840
But in this case, I just said,
go out to infinity and

00:29:40.840 --> 00:29:42.980
then we have a custom
layer created.

00:29:43.990 --> 00:29:46.940
This is the first user layer
number that you would create

00:29:46.940 --> 00:29:48.205
which happens to be 8.

00:29:48.205 --> 00:29:51.793
So the first layer that you
will create is layer 8, and

00:29:51.793 --> 00:29:54.757
you can put your objects
on custom layers, so

00:29:54.757 --> 00:29:57.565
what I mean by that,
lets come over here and

00:29:57.565 --> 00:30:00.295
lets take a cube and
on a particular cube,

00:30:00.295 --> 00:30:04.282
we can come in here and set a
layer, To be some custom layers.

00:30:04.282 --> 00:30:06.463
So let's go into
add our own layer.

00:30:06.463 --> 00:30:10.358
Notice if we added a layer
here called enemies and

00:30:10.358 --> 00:30:14.348
if I only wanted the ray
cast on the enemies layer,

00:30:14.348 --> 00:30:16.740
I would do this in code.

00:30:16.740 --> 00:30:17.490
That was layer eight.

00:30:18.780 --> 00:30:20.180
So you do a bit mask here.

00:30:20.180 --> 00:30:21.140
This is for layer eight.

00:30:21.140 --> 00:30:21.960
I explained it right here.

00:30:21.960 --> 00:30:24.045
This is a bit mask
in layer eight.

00:30:24.045 --> 00:30:29.100
So a byte has eight values and
one shifted over eight bits.

00:30:29.100 --> 00:30:34.630
It becomes one followed by seven
zeros and in that case, what we

00:30:34.630 --> 00:30:36.760
just looked at, the cubes would
be the only thing on the layer.

00:30:36.760 --> 00:30:38.510
So we would ignore
everything else.

00:30:38.510 --> 00:30:39.750
In the case of the zombies,

00:30:39.750 --> 00:30:42.650
we have only the player
that exists on layer eight.

00:30:42.650 --> 00:30:44.760
So the zombies will ignore
all the other zombies that

00:30:44.760 --> 00:30:46.720
they hit and any other
geometry in our scene, and

00:30:46.720 --> 00:30:49.700
will only return if we happen to
shoot an arrow out to the left

00:30:49.700 --> 00:30:50.830
and we hit the player.

00:30:50.830 --> 00:30:52.810
Really, really stupid simple AI,
but

00:30:52.810 --> 00:30:53.730
it's actually quite effective.

00:30:55.530 --> 00:30:57.450
All right, so hopefully
you can see raycasting.

00:30:57.450 --> 00:30:58.710
It's a really simple technique.

00:30:58.710 --> 00:31:02.698
If you want to do this on
a mobile device for example,

00:31:02.698 --> 00:31:07.505
there's code where you can just
basically use input.touch,

00:31:07.505 --> 00:31:11.767
and you can get wherever you
touched on this screen, and

00:31:11.767 --> 00:31:13.504
convert to a raycast.

00:31:13.504 --> 00:31:17.397
And also you'll notice that on
the event system that's used on

00:31:17.397 --> 00:31:21.216
the Unity AI, there happens to
be built in code there that will

00:31:21.216 --> 00:31:24.830
actually translate what you're
touching on the screen.

00:31:24.830 --> 00:31:27.300
So, you might think that you
have to do this on a button,

00:31:27.300 --> 00:31:27.945
for example.

00:31:27.945 --> 00:31:31.830
It's slightly off-subject,
but related.

00:31:31.830 --> 00:31:34.290
If I was to create a button
on the screen, let

00:31:34.290 --> 00:31:37.300
me go in the 2-D mode here, and
dock this up to the top left.

00:31:39.870 --> 00:31:40.780
And, let's go to that button.

00:31:41.830 --> 00:31:45.490
So this button right here
already has a system in place to

00:31:45.490 --> 00:31:47.920
know that you can interact
with it, you can click on it.

00:31:47.920 --> 00:31:50.620
And that is done by
the event system.

00:31:50.620 --> 00:31:53.750
It's a script and
basically will understand that

00:31:53.750 --> 00:31:55.740
when you are touching or
when you are clicking.

00:31:55.740 --> 00:31:58.320
So for example, you have
a standalone input module and

00:31:58.320 --> 00:32:01.230
a touch input module and
when you actually click

00:32:01.230 --> 00:32:03.910
on a button or touch a button
it is responsible for

00:32:03.910 --> 00:32:06.350
knowing what's there in
handling those events.

00:32:06.350 --> 00:32:09.605
So using something like this
you don't have to manually do

00:32:09.605 --> 00:32:11.520
physics.raycast.

00:32:11.520 --> 00:32:12.249
Just something to keep in mind.

00:32:18.799 --> 00:32:21.055
Now that we've talked
about raycasting,

00:32:21.055 --> 00:32:23.747
I think this is a great time
to talk about rag dolls,

00:32:23.747 --> 00:32:26.080
because the two kind of
go hand in hand to me.

00:32:26.080 --> 00:32:29.830
Now one thing I want to touch
upon with raycasting is,

00:32:29.830 --> 00:32:32.310
when you shoot a bullet
out of something,

00:32:32.310 --> 00:32:35.270
rather than shooting a real
projectile super fast,

00:32:35.270 --> 00:32:38.030
you can show a little
particle effect, like sparks.

00:32:38.030 --> 00:32:40.880
And then just raycast out to
see if you've hit an object.

00:32:40.880 --> 00:32:43.090
You don't actually have
to shoot a projectile and

00:32:43.090 --> 00:32:47.510
have that extra moving object
tax the physics system.

00:32:47.510 --> 00:32:49.290
You just do a ray cast out and
see what you hit.

00:32:50.570 --> 00:32:52.730
Now, in this demo, that's
exactly what we're gonna do.

00:32:52.730 --> 00:32:55.490
It's pretty basic, but we have
these walking soldiers, and

00:32:55.490 --> 00:32:56.500
notice, that guy there,

00:32:56.500 --> 00:33:00.585
if I click on him,
and I can shoot him.

00:33:00.585 --> 00:33:03.170
[LAUGH] And notice, he gets
this kind of crazy reaction,

00:33:03.170 --> 00:33:04.470
depending on where we
shoot him and when.

00:33:04.470 --> 00:33:06.590
Like there, that's a little
bit better looking one,

00:33:06.590 --> 00:33:08.910
little more realistic,
I should say.

00:33:08.910 --> 00:33:13.140
So, we've just shot that object.

00:33:13.140 --> 00:33:15.680
And you'll notice some of
them are actually zombies.

00:33:15.680 --> 00:33:18.510
I think the logic goes,
that some of them, when they

00:33:18.510 --> 00:33:21.090
come to life, they have a random
state, where it's a zombie.

00:33:22.190 --> 00:33:25.980
And so that just turned
the zombie into a rag doll and

00:33:25.980 --> 00:33:28.250
just essentially killed
the zombie so to say.

00:33:28.250 --> 00:33:30.360
So it's a fun effect and
you can experiment with

00:33:30.360 --> 00:33:33.410
different physics that all
is actually pretty easy but

00:33:33.410 --> 00:33:36.000
you need to have it set
up in a particular way.

00:33:36.000 --> 00:33:38.320
Now if we look at this here.

00:33:38.320 --> 00:33:40.020
This is a soldier that
is not a rag doll.

00:33:40.020 --> 00:33:41.760
It's a 3D Model.

00:33:41.760 --> 00:33:46.150
And this is a standard humanoid
rig set up inside of unity.

00:33:46.150 --> 00:33:48.800
There's certain bones that have
to be in a particular order.

00:33:48.800 --> 00:33:52.940
You have your hips, your legs,
your foot, your spine.

00:33:52.940 --> 00:33:54.750
Spine one, all down the line.

00:33:54.750 --> 00:33:57.709
You basically have this set
up for your humanoid rigs.

00:33:59.350 --> 00:34:01.640
On the rag doll side,
I'll just create one, actually.

00:34:02.840 --> 00:34:06.040
You can go 3-D object under
the game object menu and create

00:34:06.040 --> 00:34:08.180
a rag doll and you get the rag
doll wizard that pops up.

00:34:09.210 --> 00:34:12.220
You basically need to drag all
the bones from your hierarchy

00:34:12.220 --> 00:34:13.820
into their slots.

00:34:13.820 --> 00:34:17.370
So, this really should use and
object that has

00:34:17.370 --> 00:34:22.320
all of these standard
humanoid bone locations.

00:34:22.320 --> 00:34:27.030
So you can take, for example,
let's look over here Left Foot

00:34:28.160 --> 00:34:29.900
and take that transfer
on the Left Foot.

00:34:31.050 --> 00:34:34.520
What about the Left Leg?

00:34:34.520 --> 00:34:36.620
Sometimes you have to map and
just kind of figure out, okay,

00:34:36.620 --> 00:34:39.130
the left leg might be this one.

00:34:39.130 --> 00:34:42.400
If you look at the left
leg on the soldier and

00:34:42.400 --> 00:34:44.090
see exactly what that points to.

00:34:45.360 --> 00:34:46.680
So we have that location there.

00:34:47.860 --> 00:34:51.840
Left Hips and

00:34:51.840 --> 00:34:54.800
map on down the line to try
to figure everything out.

00:34:54.800 --> 00:34:57.040
Now if we look at what I've
mapped on this guy here.

00:34:58.650 --> 00:35:01.870
Once I've done the mapping and
you drag everything into place,

00:35:01.870 --> 00:35:04.160
you can see,
let me close this one out.

00:35:05.260 --> 00:35:08.830
Once you create the mapping
it actually creates a capsule

00:35:08.830 --> 00:35:11.410
collider, a rigid body and

00:35:11.410 --> 00:35:15.540
a joint on each particular
area of that object.

00:35:15.540 --> 00:35:20.540
So, right here,
We can see that a child of

00:35:20.540 --> 00:35:23.170
the hips there's actually all
these different colliders.

00:35:23.170 --> 00:35:26.430
So on the actual left leg,
let's see how this is broken up.

00:35:27.530 --> 00:35:29.410
This will give us an idea how to
set the other one up, actually.

00:35:32.020 --> 00:35:35.100
All right, on the toes
we don't have anything.

00:35:35.100 --> 00:35:36.410
On our left foot,
we don't have anything.

00:35:36.410 --> 00:35:41.461
On our left leg,
we have a rigid body,

00:35:41.461 --> 00:35:43.290
and a joint and
a capsule collider.

00:35:44.980 --> 00:35:48.780
Left up leg is where we have our
second grouping, so to say, our

00:35:48.780 --> 00:35:52.710
second capsule collider, which
is body and character joint.

00:35:52.710 --> 00:35:54.590
And then we can go over
to the right leg and

00:35:54.590 --> 00:35:56.180
then let's work from
the spine down.

00:35:57.680 --> 00:36:02.664
Spine one, spine two and
neck, neck, head.

00:36:02.664 --> 00:36:06.910
Okay there's our head and same
thing on that with our right

00:36:06.910 --> 00:36:09.750
arm, right forearm, and
we can see the mapping here.

00:36:09.750 --> 00:36:12.200
So the forearm has
a collider on it.

00:36:12.200 --> 00:36:15.040
The upper arm, which is
called right arm, has it.

00:36:15.040 --> 00:36:16.310
The shoulder does not have one.

00:36:16.310 --> 00:36:20.260
So using this, let's go
back over to the rag doll,

00:36:20.260 --> 00:36:23.290
what we should configure
is a rag doll I should say.

00:36:23.290 --> 00:36:24.360
And go back to our wizard.

00:36:25.390 --> 00:36:27.070
Choose rag doll.

00:36:27.070 --> 00:36:28.540
And notice we have
the head that we need.

00:36:30.440 --> 00:36:31.860
So the head was
underneath the spine.

00:36:33.460 --> 00:36:33.960
Neck.

00:36:36.080 --> 00:36:37.780
And head, so there's our head.

00:36:37.780 --> 00:36:39.650
Now you notice if,
this might take a little bit

00:36:39.650 --> 00:36:41.519
to get right depending on
how your model's setup.

00:36:42.670 --> 00:36:46.310
What can happen is if you don't
have them set up in the proper

00:36:46.310 --> 00:36:49.910
order your objects won't
work right when they

00:36:49.910 --> 00:36:51.460
basically need to
turn to rag doll.

00:36:51.460 --> 00:36:54.540
You might see things stretching
in a weird way or acting super,

00:36:54.540 --> 00:36:56.150
super goofy.

00:36:56.150 --> 00:36:58.700
So let's look at where
our middle spine is here.

00:37:01.270 --> 00:37:03.360
Take our spine translate
that over here.

00:37:03.360 --> 00:37:04.950
And so on down the line.
I'm not going to set

00:37:04.950 --> 00:37:06.700
every one of them up here
because I've already done all

00:37:06.700 --> 00:37:07.510
the other objects.

00:37:07.510 --> 00:37:10.020
Just to give you an idea
of how to set this up.

00:37:10.020 --> 00:37:10.800
Now there's a mass for

00:37:10.800 --> 00:37:14.040
the objects since of course
our forces can affect our

00:37:14.040 --> 00:37:15.740
objects in different ways
depending on their mass.

00:37:16.750 --> 00:37:17.790
But we have a challenge now.

00:37:17.790 --> 00:37:21.880
As soon as this object comes to
life, it is a rigid body, and

00:37:21.880 --> 00:37:23.670
it has colliders on there,
and joints.

00:37:23.670 --> 00:37:25.090
It's gonna just
fall to the ground.

00:37:26.110 --> 00:37:28.880
So, what we need to do is just
disable all of those objects

00:37:28.880 --> 00:37:31.810
when we start this game up,
when it comes to life.

00:37:31.810 --> 00:37:34.690
And then, when the time comes,

00:37:34.690 --> 00:37:39.940
then we should go ahead and
disable our rigid bodies.

00:37:39.940 --> 00:37:45.830
So what I do is when our code
starts here, I basically inside

00:37:45.830 --> 00:37:49.312
of start on this game object,
and we can do this in awake as

00:37:49.312 --> 00:37:53.730
well, we find all the rigid body
components in our children.

00:37:53.730 --> 00:37:54.970
In other words,

00:37:54.970 --> 00:37:58.350
our soldier controller is
on a root game object here.

00:37:58.350 --> 00:38:01.230
And when it starts up it says,
okay, give me all of the rigid

00:38:01.230 --> 00:38:03.650
boy components in all
of these children, and

00:38:03.650 --> 00:38:07.190
then for each one, we turn it
into a kinematic rigid body.

00:38:07.190 --> 00:38:10.360
So we've spoken about kinematic
rigid bodies already.

00:38:10.360 --> 00:38:15.140
And, looking down the line here,
rigid body, right now we are in

00:38:15.140 --> 00:38:18.580
design mode, in the editor,
so it is not kinematic.

00:38:18.580 --> 00:38:19.710
Let's go ahead and play this.

00:38:19.710 --> 00:38:23.750
And you'll see right
away in that first frame,

00:38:23.750 --> 00:38:26.220
all of these are kinematic
rigidBodies.

00:38:26.220 --> 00:38:30.590
So as soon as this object starts
up, physics are disabled.

00:38:30.590 --> 00:38:33.880
In other words, the kinematic
rigidBody is enabled, and

00:38:33.880 --> 00:38:35.669
all of the physics
interactions are disabled.

00:38:36.810 --> 00:38:39.040
And then our object can walk
around and it can move.

00:38:39.040 --> 00:38:41.020
Which really just
has some super,

00:38:41.020 --> 00:38:43.240
super basic code just to
start walking around.

00:38:43.240 --> 00:38:45.150
It's actually not even
using these navigation.

00:38:45.150 --> 00:38:46.580
In this particular one,

00:38:46.580 --> 00:38:50.930
if I recall, I'm just simply
setting the transform.

00:38:50.930 --> 00:38:52.340
And here we go,
transform to translate.

00:38:52.340 --> 00:38:55.130
And I'm just moving forward on
whatever direction it happens to

00:38:55.130 --> 00:38:56.140
be rotating in.

00:38:56.140 --> 00:38:57.880
So just really, really,
really basic for the demo.

00:38:57.880 --> 00:39:01.960
Now where this becomes a little
bit interesting is when we

00:39:01.960 --> 00:39:02.570
get hit.

00:39:05.620 --> 00:39:06.930
So, let's look for iskinematic.

00:39:08.290 --> 00:39:11.130
And there's a symbol state
machine here which is a function

00:39:11.130 --> 00:39:12.930
called changeState.

00:39:14.240 --> 00:39:17.720
And when the object gets killed,
for

00:39:17.720 --> 00:39:19.880
example, KillZombie because
these are soldier zombies.

00:39:19.880 --> 00:39:20.380
I mean, why not?

00:39:21.750 --> 00:39:24.350
Let's find all of our references
are project to KillZombie, and

00:39:24.350 --> 00:39:26.260
we see that when we raycast.

00:39:28.730 --> 00:39:29.980
There we go.

00:39:29.980 --> 00:39:32.710
So we raycast,
whenever we do Fire1.

00:39:32.710 --> 00:39:34.610
The same code we
looked at before.

00:39:34.610 --> 00:39:35.920
Fire1.

00:39:35.920 --> 00:39:38.070
We get our mouse position and
we convert it to a ray.

00:39:39.210 --> 00:39:44.400
We shoot out a Raycast and
on the object we've hit,

00:39:44.400 --> 00:39:46.900
we attempt to get
a SoldierController.

00:39:46.900 --> 00:39:50.420
If it's there, hey we know it's
a soldier, a zombie soldier.

00:39:50.420 --> 00:39:52.872
And we call a method on it,
called KillZombie.

00:39:52.872 --> 00:39:57.040
KillZombie calls into its little
state logic called ChangeState.

00:39:57.040 --> 00:39:59.358
This is our code,
not Unity's code.

00:39:59.358 --> 00:40:01.457
SoldierState.Killed.

00:40:01.457 --> 00:40:05.243
And we have some logic to make
sure we can't go from killed to

00:40:05.243 --> 00:40:06.700
running for example.

00:40:08.160 --> 00:40:11.160
And as soon as we go to killed,
we set a couple of variables

00:40:11.160 --> 00:40:17.520
here, we stop our moving around,
we stop our randomizing code.

00:40:17.520 --> 00:40:20.050
Now here's the interesting part
that's related specifically to

00:40:20.050 --> 00:40:21.370
the rag doll.

00:40:21.370 --> 00:40:24.410
We do the opposite of what we
did when we started our code up.

00:40:24.410 --> 00:40:28.590
We asked for all the components
in this ragdolls children.

00:40:28.590 --> 00:40:30.720
And we turn off isKinematic.

00:40:30.720 --> 00:40:33.340
In other words,
physics will now take over.

00:40:34.450 --> 00:40:37.340
And we also disable the animator
because that would then fight

00:40:37.340 --> 00:40:39.160
with our physic system.

00:40:39.160 --> 00:40:41.280
So make sure you turn
off your animations and

00:40:41.280 --> 00:40:43.610
allow the physics to
take over the ragdoll.

00:40:43.610 --> 00:40:44.878
So let's go ahead and
see what this looks like.

00:40:48.708 --> 00:40:50.170
There we go, perfect.

00:40:50.170 --> 00:40:55.320
And so at that point in time
our animator is disabled.

00:40:55.320 --> 00:40:57.180
Physics is re-enabled again.

00:40:57.180 --> 00:40:57.866
Let's do that one more time.

00:41:01.268 --> 00:41:03.218
[LAUGH] Sometimes you get
these kind of tweaks,

00:41:03.218 --> 00:41:05.640
depending on the position
the character was in.

00:41:05.640 --> 00:41:07.620
But you notice it was kinda
funny, that object went kinda

00:41:07.620 --> 00:41:10.260
flying off because the force
that was applied to it.

00:41:10.260 --> 00:41:11.718
And let's go ahead and
find that one here.

00:41:17.508 --> 00:41:19.230
This one right there.

00:41:19.230 --> 00:41:23.544
And if we look at all
the various attributes of this

00:41:23.544 --> 00:41:27.768
soldier, so lets look at
the rigid bodies here.

00:41:27.768 --> 00:41:32.569
Notice is isKinematic is
no longer checked off, so

00:41:32.569 --> 00:41:37.483
this object is now under
the influence of gravity and

00:41:37.483 --> 00:41:39.730
we can allow it to fall.

00:41:39.730 --> 00:41:43.670
In this particular case with
our rigid bodies kinematic,

00:41:43.670 --> 00:41:46.150
what can happen too is
these joints can kind of,

00:41:46.150 --> 00:41:47.470
depending on how you
have them set up,

00:41:47.470 --> 00:41:49.478
they can twist with each other,
they can affect each other.

00:41:49.478 --> 00:41:51.600
You can fine-tune this
operation a little bit, and

00:41:51.600 --> 00:41:54.510
you can see that it happens
a little bit randomly here.

00:41:54.510 --> 00:41:56.940
So for example there, that
one will look perfectly good.

00:41:59.230 --> 00:42:01.745
Let's try it again and see if we
can't get it to tweak up again.

00:42:01.745 --> 00:42:03.637
[LAUGH] So that case.

00:42:03.637 --> 00:42:05.680
[LAUGH] That was a good one.

00:42:05.680 --> 00:42:07.020
Popped over the edge
he currently was

00:42:07.020 --> 00:42:08.470
running when it happened.

00:42:08.470 --> 00:42:10.660
So again, you can control
this process a little bit.

00:42:12.040 --> 00:42:15.290
But hopefully you can see
that by a ray cast and

00:42:15.290 --> 00:42:17.300
enabling all the rigid
bodies here,

00:42:17.300 --> 00:42:20.150
you can really get a pretty cool
effect with these rag dolls.

00:42:20.150 --> 00:42:20.750
Pretty easy to set up.

00:42:23.108 --> 00:42:27.370
In the last module I covered
2D physics materials briefly.

00:42:27.370 --> 00:42:29.352
I want to make this
a little more official and

00:42:29.352 --> 00:42:31.170
cover it just a tad
more in depth here.

00:42:32.260 --> 00:42:35.090
With physics materials you
are specifying either a 2D or

00:42:35.090 --> 00:42:37.750
a 3D material that is
applied to a collider.

00:42:37.750 --> 00:42:39.970
To define your bounciness and

00:42:39.970 --> 00:42:44.850
friction of really how that
substance might work, is it ice?

00:42:44.850 --> 00:42:46.920
Should it act like sandpaper?

00:42:46.920 --> 00:42:49.360
Should it have a high
friction coefficient?

00:42:49.360 --> 00:42:52.285
Maybe you want not
your bounce or

00:42:52.285 --> 00:42:55.455
friction to change, but
maybe your actual object

00:42:55.455 --> 00:42:58.505
that's falling you might need
to change at a different rate.

00:42:58.505 --> 00:43:00.880
So there's a couple different
ways before you immediately

00:43:00.880 --> 00:43:02.743
things that,
I want my object to slow down.

00:43:02.743 --> 00:43:04.812
Should I change its
physics material?

00:43:05.862 --> 00:43:07.792
There's a couple of
things to keep in mind.

00:43:07.792 --> 00:43:09.692
If this object is
touching a surface and

00:43:09.692 --> 00:43:11.522
that surface should slow down or

00:43:11.522 --> 00:43:14.272
change the way that object
interacts with it, then yes.

00:43:14.272 --> 00:43:15.292
Change your physics material.

00:43:15.292 --> 00:43:18.042
Make it bouncier,
make it have a higher friction.

00:43:18.042 --> 00:43:20.872
If your object should fall
at a different rate or

00:43:20.872 --> 00:43:24.270
should act at a different rate
across a variety of surfaces,

00:43:24.270 --> 00:43:27.380
then in that case physics
material is not the answer but

00:43:27.380 --> 00:43:31.220
in that case you can change
your drag on your rigid body.

00:43:31.220 --> 00:43:33.200
Let's go right into Unity and
check out what I mean here.

00:43:35.290 --> 00:43:38.130
This is our 2D scene here
that has a basic example

00:43:38.130 --> 00:43:43.330
of this really tall shelf here
that Yeti will come and fall on.

00:43:43.330 --> 00:43:46.905
And right off the bat
Yeti will hit this and

00:43:46.905 --> 00:43:50.155
then Yeti will not fall
because what happens is,

00:43:50.155 --> 00:43:53.830
once we go in the 2D mode,
what happens is Yeti hits that,

00:43:53.830 --> 00:43:57.200
this particular material
has a very high friction.

00:43:57.200 --> 00:43:58.030
Yeti just stops.

00:43:58.030 --> 00:44:01.951
If we look at our material,
it has a friction of 10 and

00:44:01.951 --> 00:44:03.328
bounciness of 0.

00:44:03.328 --> 00:44:06.389
Creating these materials, as we
looked at in the last module,

00:44:06.389 --> 00:44:08.644
it is literally
right-clicking and saying,

00:44:08.644 --> 00:44:10.894
I want a Physic Material,
which is for 3D, or

00:44:10.894 --> 00:44:13.610
Physics2D Material,
which is used for 2D.

00:44:13.610 --> 00:44:17.790
I also use this in here, for

00:44:17.790 --> 00:44:20.850
the kinematic demo that
we looked at before.

00:44:20.850 --> 00:44:24.180
The pillar in here,
shows us about a good

00:44:24.180 --> 00:44:29.450
starting spot because our object
right next to it you'll notice

00:44:29.450 --> 00:44:33.100
this cube right here has
a little bit of a bounce to it.

00:44:33.100 --> 00:44:38.500
So this material has friction
of 0.6 and a bounciness of 1.

00:44:38.500 --> 00:44:41.555
Notice you get a couple more
options for 3D objects as well.

00:44:41.555 --> 00:44:43.173
How you should combine
your friction,

00:44:43.173 --> 00:44:44.700
how you should
combine your bounce.

00:44:46.940 --> 00:44:48.480
Dynamic friction,
static friction, so

00:44:48.480 --> 00:44:50.872
when you're moving or
when you're stopped.

00:44:50.872 --> 00:44:56.310
Now notice this object kind of
has a bit more of a bounce here.

00:44:56.310 --> 00:44:58.560
Let's actually disable this
pillar so you can see it.

00:45:00.900 --> 00:45:01.880
I'll pick this guy up.

00:45:03.290 --> 00:45:06.440
Now notice this one bounces
a lot more than the other one on

00:45:06.440 --> 00:45:07.060
this surface.

00:45:07.060 --> 00:45:08.570
Let's try that again here.

00:45:08.570 --> 00:45:13.792
You'll see the other one
come down and notice

00:45:13.792 --> 00:45:18.750
this one gets a little
bit jumpier coming down.

00:45:18.750 --> 00:45:21.180
So that's because this
particular object

00:45:21.180 --> 00:45:23.900
has the bouncy material on it.

00:45:23.900 --> 00:45:27.902
So really, really, really
easy to set but now maybe,

00:45:27.902 --> 00:45:32.426
instead, we have our bouncy
material but on this rigid body,

00:45:32.426 --> 00:45:35.218
let's crank up drag to say 1000.

00:45:40.058 --> 00:45:41.448
Now I'll take this object up.

00:45:41.448 --> 00:45:45.214
Notice this effects,
not just on a surface but

00:45:45.214 --> 00:45:46.958
also in the air here.

00:45:46.958 --> 00:45:51.188
So the drag on this
rigid body is huge,

00:45:51.188 --> 00:45:57.414
let's go ahead and try to
crank this down to maybe 50.

00:45:57.414 --> 00:46:00.774
Still way too high, 3.

00:46:00.774 --> 00:46:02.574
I hit that surface and
I just stop.

00:46:05.118 --> 00:46:09.670
Try that as a 2, there we go.

00:46:09.670 --> 00:46:12.100
Now we're kind of getting
back to a little bit more

00:46:12.100 --> 00:46:13.000
reality so to say.

00:46:14.950 --> 00:46:17.670
But notice it has just
a little bit more

00:46:17.670 --> 00:46:19.500
tension then the other one had.

00:46:19.500 --> 00:46:20.830
This one just
bounces right away.

00:46:20.830 --> 00:46:23.440
Even though this one has
the exact same bouncy material,

00:46:25.120 --> 00:46:27.450
it's got that extra drag and it
doesn't bounce nearly as high.

00:46:27.450 --> 00:46:31.350
It's almost like it has,
sandpaper on it, so to say.

00:46:31.350 --> 00:46:34.970
So you might wanna tweak with
this particular object's drag

00:46:34.970 --> 00:46:38.360
as well, even though you
might think you wanna change

00:46:38.360 --> 00:46:40.700
your physics material setting.

00:46:40.700 --> 00:46:42.710
Instead you might wanna
actually change your drag

00:46:42.710 --> 00:46:43.590
on that particular object.

00:46:45.520 --> 00:46:46.660
Effectors are pretty simple,

00:46:46.660 --> 00:46:49.910
they just apply
forces to 2D objects.

00:46:49.910 --> 00:46:52.490
There's no effectors for
3D objects.

00:46:52.490 --> 00:46:55.240
They are only for 2D objects,
and we have an area,

00:46:55.240 --> 00:46:58.330
buoyancy, platform,
point, and surface.

00:46:58.330 --> 00:47:00.916
The best way to describe these
is to simply show you demo, so

00:47:00.916 --> 00:47:02.276
let me show you that right now.

00:47:04.508 --> 00:47:07.519
In this demo, my little vamp kid
verses zombie apocalypse scene

00:47:07.519 --> 00:47:10.318
here, is gonna experience
a couple different effectors.

00:47:10.318 --> 00:47:13.732
This poor little zombie guy when
I play, he's gonna fall down and

00:47:13.732 --> 00:47:17.400
hit this particular platform,
this first on here.

00:47:17.400 --> 00:47:20.160
And this has a surface effector.

00:47:20.160 --> 00:47:24.670
Now surface effector will give
you a speed along the surface.

00:47:24.670 --> 00:47:26.090
This acts like a conveyor belt.

00:47:26.090 --> 00:47:29.280
So this object will be going
four meters per second.

00:47:29.280 --> 00:47:31.380
Then we hit this
red platform here.

00:47:31.380 --> 00:47:33.120
Whoops, let me undo that.

00:47:33.120 --> 00:47:35.360
This red platform has
an area effector.

00:47:35.360 --> 00:47:39.770
An area effector applies
a force over time.

00:47:39.770 --> 00:47:44.110
So the longer an object is on
here, the faster it will go.

00:47:44.110 --> 00:47:48.220
This has a force magnitude of 8,
and so we'll see that as it's

00:47:48.220 --> 00:47:50.350
along here we'll speed up just
a little bit by little bit.

00:47:51.580 --> 00:47:54.674
Finally we come over to
our particle system, and

00:47:54.674 --> 00:47:58.758
the particle system itself is
juts a standard particle system.

00:47:58.758 --> 00:48:03.390
However what we have
right here on the actual

00:48:03.390 --> 00:48:08.920
object is we have another
area effector here.

00:48:08.920 --> 00:48:12.330
But notice this area effector
uses a force angle of 90

00:48:12.330 --> 00:48:13.590
degrees, which is what?

00:48:13.590 --> 00:48:14.620
Straight up.

00:48:14.620 --> 00:48:17.140
If we look at this one,
this has a force angle of 0.

00:48:17.140 --> 00:48:20.530
So it moves along the x-axis.

00:48:20.530 --> 00:48:22.650
This one here has a force
angle of 90 degrees.

00:48:22.650 --> 00:48:23.800
It moves up.

00:48:23.800 --> 00:48:26.260
Now on any of these objects
that use effectors,

00:48:26.260 --> 00:48:28.340
there's one thing you must do.

00:48:28.340 --> 00:48:31.030
They work in conjunction
with a collider.

00:48:31.030 --> 00:48:34.590
And notice, on the collider,
Used By Effector.

00:48:34.590 --> 00:48:36.950
So, over here,
let's just go ahead and remove,

00:48:39.710 --> 00:48:44.320
let's remove the Surface
Effector, and uncheck that.

00:48:44.320 --> 00:48:46.040
So we just have
a regular collider.

00:48:46.040 --> 00:48:50.600
Now, if we wanna turn this
into a surface effector,

00:48:50.600 --> 00:48:52.620
let's add the surface
effector and

00:48:52.620 --> 00:48:55.050
immediately we'll see,
there's a warning here.

00:48:55.050 --> 00:48:57.810
This effector will not function
until there's at least

00:48:57.810 --> 00:49:01.330
one enabled 2D collider
with use by effector

00:49:01.330 --> 00:49:02.660
checked on the scheme object.

00:49:02.660 --> 00:49:05.350
It tells you exactly
what you needed to know.

00:49:05.350 --> 00:49:09.660
Go up to the collider,
check off use by effector.

00:49:09.660 --> 00:49:10.550
That's it.

00:49:10.550 --> 00:49:14.140
Let's change the speed to 4 and
let's run this and

00:49:14.140 --> 00:49:14.810
see what's going to happen.

00:49:14.810 --> 00:49:17.660
We're gonna fall down and move
here at four meters a second.

00:49:17.660 --> 00:49:21.100
We're gonna increase our speed
slowly along this platform here.

00:49:21.100 --> 00:49:24.010
And then this is another area
effector that's gonna start to,

00:49:24.010 --> 00:49:28.040
over time, shoot up a force
in the 90 degree direction.

00:49:28.040 --> 00:49:31.570
And ideally, we should pass
through this platform.

00:49:31.570 --> 00:49:33.000
This has a platform effector.

00:49:34.610 --> 00:49:36.050
It's also another factor, but

00:49:36.050 --> 00:49:40.130
this one is specifically meant
towards platformer type games.

00:49:40.130 --> 00:49:42.760
Think of a great
game like Mario.

00:49:42.760 --> 00:49:46.135
You could jump through a surface
and then land on top of it.

00:49:46.135 --> 00:49:48.485
That is exactly what
the platform effector

00:49:48.485 --> 00:49:49.105
will do for you.

00:49:49.105 --> 00:49:52.055
It allows you to go through
a surface and land back down.

00:49:52.055 --> 00:49:53.715
You can see use one way.

00:49:53.715 --> 00:49:54.579
This is one way.

00:49:54.579 --> 00:49:58.919
We can go through it but
we'll stop coming back down.

00:49:58.919 --> 00:50:02.966
Let's see what happens.

00:50:02.966 --> 00:50:05.359
Okay, that works four
meters a second, and

00:50:05.359 --> 00:50:07.828
we should hit this and
go a little bit faster.

00:50:11.318 --> 00:50:15.900
Then we go up, and land right
there, and then we stop.

00:50:15.900 --> 00:50:17.500
My layers are a little
bit messed up here,

00:50:17.500 --> 00:50:21.740
I could surely change the zombie
character to be on a new layer.

00:50:22.740 --> 00:50:25.290
I go over this in the 2D lab,
but that's easy enough.

00:50:25.290 --> 00:50:29.812
We can add a new layer called
Player and add our zombie to

00:50:29.812 --> 00:50:33.558
the player layer which
is our topmost layer.

00:50:38.528 --> 00:50:42.712
And zombie should happily
show on top of the surfaces

00:50:42.712 --> 00:50:43.670
right now.

00:50:44.890 --> 00:50:47.430
Again, all I did was
added another layer, and

00:50:47.430 --> 00:50:49.970
that layer gets drawn on
top of everything else.

00:50:49.970 --> 00:50:52.390
There we go, our zombie's
in front of everything,

00:50:52.390 --> 00:50:56.860
it's our 90 degree effector,
our area effector, goes through

00:50:56.860 --> 00:50:59.920
the platform effector, and
lands on top and stops.

00:50:59.920 --> 00:51:01.160
Now there's other ones
that I didn't demo

00:51:01.160 --> 00:51:04.050
like the Point Effector and
a Buoyancy Effector, which just

00:51:04.050 --> 00:51:06.030
allows things to act like
they're floating in 2D water.

00:51:06.030 --> 00:51:07.950
Really cool demos.

00:51:07.950 --> 00:51:10.860
But I just wanna show you the
basics of what effectors are so

00:51:10.860 --> 00:51:11.670
you can understand them.

00:51:11.670 --> 00:51:13.800
And we have a lot that we've
covered so far in here.

00:51:13.800 --> 00:51:16.550
Let's move on to our
final subject where

00:51:16.550 --> 00:51:17.889
we're gonna talk about joints.

00:51:20.170 --> 00:51:22.670
For this demo I have
two joints set up here.

00:51:22.670 --> 00:51:24.650
A hinge joint and
a spring joint.

00:51:24.650 --> 00:51:26.660
Sometimes they can act
a little bit like each other.

00:51:28.020 --> 00:51:31.330
If we look at an actual hinge
joint, our segments of a hinge

00:51:31.330 --> 00:51:34.350
joint are created by we
have a capsule collider.

00:51:34.350 --> 00:51:36.300
In this particular case we could

00:51:36.300 --> 00:51:37.930
have a different
type of collider.

00:51:37.930 --> 00:51:41.580
We have a rigid body that
is set to use gravity.

00:51:41.580 --> 00:51:43.790
But notice it's
not is kinematic,

00:51:43.790 --> 00:51:45.540
it's a regular rigid body, but

00:51:45.540 --> 00:51:49.630
it happens to be connected
to a kinematic rigid body.

00:51:49.630 --> 00:51:51.080
That's its base here.

00:51:51.080 --> 00:51:53.170
That's because the base
is a floating platform.

00:51:54.440 --> 00:51:56.060
It should not be under
the influence of gravity.

00:51:56.060 --> 00:51:57.500
It's a kinematic rigid body.

00:51:58.620 --> 00:52:01.820
If we look at segment number
one, the first segment

00:52:01.820 --> 00:52:05.990
in our hinge joint, these are
all joints going down the line.

00:52:05.990 --> 00:52:09.520
Notice that that first segment,
it needs to know what it's

00:52:09.520 --> 00:52:13.410
connected to and what type of
object is that, a rigid body.

00:52:13.410 --> 00:52:15.830
I only have two choices,
it's either a kinematic or

00:52:15.830 --> 00:52:16.540
it's not a kinematic.

00:52:17.620 --> 00:52:19.090
In this case I don't
want it to fall,

00:52:19.090 --> 00:52:20.300
it's not resting on the ground,
so

00:52:20.300 --> 00:52:22.380
it needs to be
a kinematic rigid body.

00:52:22.380 --> 00:52:24.220
So that's another case for
kinematic rigid body.

00:52:24.220 --> 00:52:28.450
Going down the line here,
we look at Segment2,

00:52:28.450 --> 00:52:30.280
we have our hinge joint.

00:52:30.280 --> 00:52:31.880
And Segment3,
we have our hinge joint.

00:52:33.680 --> 00:52:38.400
When we run this notice I get a
couple degrees of freedom here.

00:52:38.400 --> 00:52:41.160
So if we look at
this top one here.

00:52:41.160 --> 00:52:42.260
And let me just move
it a little bit.

00:52:42.260 --> 00:52:44.310
I'll probably break
it in the process.

00:52:44.310 --> 00:52:47.500
But notice I get three degrees
of freedom, x y and z.

00:52:47.500 --> 00:52:48.860
This is moving all
over the place here.

00:52:50.610 --> 00:52:54.390
If I only want this to
swing like it's fixed in

00:52:56.070 --> 00:52:58.625
a joint here that can
only move in the Z axis.

00:52:59.870 --> 00:53:01.040
We can go and

00:53:01.040 --> 00:53:04.570
change exactly which
directions we can rotate in.

00:53:04.570 --> 00:53:05.870
Notice right here we have one,
one,

00:53:05.870 --> 00:53:08.400
one in our axes which
directions we can rotate in.

00:53:10.010 --> 00:53:14.590
Let's make that zero, zero,
one and play that now, and

00:53:14.590 --> 00:53:18.360
notice that the hinge should
only rotate this way.

00:53:20.210 --> 00:53:21.050
There we go.

00:53:21.050 --> 00:53:23.830
Just kind of left right there so
our Z is our depth and we can

00:53:23.830 --> 00:53:26.650
see that we're pin essentially
right through Z there

00:53:26.650 --> 00:53:28.850
at the top which happens
to be the anchor point.

00:53:31.820 --> 00:53:37.780
So we can change notice where
we happen to be anchored at.

00:53:37.780 --> 00:53:41.360
So there it thinks that's
it's anchor point.

00:53:41.360 --> 00:53:43.030
And right now I'm
moving it up so

00:53:43.030 --> 00:53:46.630
it acts like it's anchored
right up top there.

00:53:46.630 --> 00:53:48.050
So that's what
the anchor is for.

00:53:48.050 --> 00:53:50.440
The location that it's going
to act like it's pinned at.

00:53:54.190 --> 00:53:55.710
So these are pretty basic.

00:53:55.710 --> 00:53:57.520
We have our base.

00:53:57.520 --> 00:54:00.610
We have a segment that's
connected through a hinge joint

00:54:00.610 --> 00:54:01.780
to the base.

00:54:01.780 --> 00:54:04.330
We specify what degrees of
freedom we want to give it,

00:54:04.330 --> 00:54:07.430
we're only going to
rotate in the z.

00:54:07.430 --> 00:54:09.060
We specify where the anchor is,

00:54:09.060 --> 00:54:11.930
the point this should
essentially be fixed off of.

00:54:11.930 --> 00:54:13.180
And then we just go
down the line, and

00:54:13.180 --> 00:54:14.750
we do the same thing for
each particular one.

00:54:14.750 --> 00:54:17.800
And lastly we have our sphere.

00:54:19.510 --> 00:54:22.166
Now our break force on there,
if we look at segment1,

00:54:22.166 --> 00:54:26.020
notice it's infinity which means
it won't break off the base.

00:54:26.020 --> 00:54:28.868
Segment 2 has a break
force of 200.

00:54:28.868 --> 00:54:31.990
And segment 3 is infinity.

00:54:31.990 --> 00:54:33.080
And our sphere is infinity.

00:54:33.080 --> 00:54:34.960
Which means it will
only ever break between

00:54:34.960 --> 00:54:36.880
these two segments right here.

00:54:36.880 --> 00:54:38.480
Let's test out that theory.

00:54:38.480 --> 00:54:40.175
And let's grab our ball here.

00:54:40.175 --> 00:54:41.432
There we go.

00:54:41.432 --> 00:54:44.640
[LAUGH] So you can tell it just
ripped off right at that point.

00:54:45.790 --> 00:54:47.296
Now our next case here is, and

00:54:47.296 --> 00:54:50.258
it's acting a little bit
differently, we have a spring.

00:54:52.448 --> 00:54:54.930
And you can see
the stretch in here.

00:54:54.930 --> 00:54:57.510
Let's go ahead and
just move this up a little bit.

00:54:57.510 --> 00:54:59.200
You can see,
it really looks like there's

00:54:59.200 --> 00:55:00.810
like kind of a spring
wobble in there.

00:55:00.810 --> 00:55:03.480
It looks very different
than the way that

00:55:03.480 --> 00:55:05.310
this particular one is acting.

00:55:05.310 --> 00:55:08.520
Now aside of the fact
it breaks really easy.

00:55:08.520 --> 00:55:10.840
So this one is a spring joint.

00:55:10.840 --> 00:55:12.220
We have the same thing.

00:55:12.220 --> 00:55:14.520
We have a cube that
acts as its base,

00:55:14.520 --> 00:55:15.750
it's a kinematic rigid body.

00:55:16.950 --> 00:55:20.800
Our first capsule here
is a fixed joint, and

00:55:20.800 --> 00:55:24.460
notice it's connected to
our kinematic rigid body.

00:55:24.460 --> 00:55:27.590
That's the top of it, has
a break force of infinity, so

00:55:27.590 --> 00:55:28.559
that one won't break off.

00:55:30.400 --> 00:55:33.590
Next on the line we
have a spring joint and

00:55:33.590 --> 00:55:38.250
this has our spring value here
of 1000 and all the various

00:55:38.250 --> 00:55:41.820
distances on how much you can
stretch, how it can react.

00:55:41.820 --> 00:55:46.110
Same thing for the next one and
down to our sphere as well.

00:55:46.110 --> 00:55:47.300
All spring joints.

00:55:47.300 --> 00:55:49.190
On this one I have a little
generic script on here that

00:55:49.190 --> 00:55:50.950
every time you click,

00:55:50.950 --> 00:55:53.510
Kind of we'll just
accelerate it a little bit,

00:55:53.510 --> 00:55:57.290
just to try to debug and see if
we can't get it to break off.

00:55:57.290 --> 00:56:00.610
But the way that it does
that is every time you click

00:56:00.610 --> 00:56:02.510
it's adding a force
to the spring.

00:56:05.240 --> 00:56:09.020
So when you click, it gets
the rigid body and then it adds

00:56:09.020 --> 00:56:14.350
a force to it in the right
direction, of type acceleration.

00:56:14.350 --> 00:56:17.460
Just a really generic way to
add a force to a game object.

00:56:19.260 --> 00:56:20.010
Why, you say?

00:56:20.010 --> 00:56:21.810
Why do I have that
code in there?

00:56:21.810 --> 00:56:24.840
Just as a little challenge to
see how these springs can react,

00:56:24.840 --> 00:56:27.860
and if you can get one to go and
break off the other one.

00:56:27.860 --> 00:56:31.770
Now the other one has not
the best break force so it might

00:56:31.770 --> 00:56:34.970
take a little bit, but once you
kind of get it rolling around.

00:56:34.970 --> 00:56:37.220
We saw in the demo before,
this is pretty easy to break.

00:56:38.740 --> 00:56:39.850
Just go like that, snap.

00:56:44.540 --> 00:56:48.700
Now, we also saw this in the
demo earlier in our kinematic

00:56:48.700 --> 00:56:51.390
demo, although its gonna be
basically the same thing here.

00:56:51.390 --> 00:56:54.290
This is just nothing more
than a hinge joint that's

00:56:54.290 --> 00:56:58.410
floating in front of our scene
here that we ended up shooting.

00:56:58.410 --> 00:57:00.760
I'm sorry not that one,
in our discrete demo.

00:57:02.820 --> 00:57:04.850
This had the same hinge joint
in the beginning here that

00:57:04.850 --> 00:57:06.050
we can shoot at.

00:57:06.050 --> 00:57:06.790
Nothing different there.

00:57:08.560 --> 00:57:10.719
Now lastly let's go ahead and
look at a fixed joint.

00:57:14.490 --> 00:57:19.610
In this scene we have a plank
here, this plank is not

00:57:19.610 --> 00:57:23.350
a kinematic rigid body, but it
does not have gravity enabled,

00:57:23.350 --> 00:57:25.110
so it's just sitting
there in space.

00:57:25.110 --> 00:57:27.370
And the same thing for
this side.

00:57:27.370 --> 00:57:29.220
It's just a regular rigid body,
but

00:57:29.220 --> 00:57:30.569
it does not have
gravity enabled.

00:57:31.590 --> 00:57:35.830
Now both of these objects
have a box collider on them.

00:57:35.830 --> 00:57:40.240
And notice that the plank has
a fixed joint to connect it to

00:57:40.240 --> 00:57:44.610
this rigid body which is
this connected wall here.

00:57:45.640 --> 00:57:48.260
What's gonna happen is we
specified a break force of ten

00:57:49.290 --> 00:57:52.420
and this ball that's up on
top is going to fall down and

00:57:52.420 --> 00:57:54.100
break our settings for us.

00:57:54.100 --> 00:57:54.600
Check this out.

00:57:57.338 --> 00:58:01.090
Frame advance, advance advance
advance advance [LAUGHS].

00:58:01.090 --> 00:58:03.476
As soon as we get to
this location here.

00:58:07.038 --> 00:58:07.900
All right, Boom.

00:58:11.750 --> 00:58:14.260
Notice, it's very subtle here,
but we've already started to

00:58:14.260 --> 00:58:16.130
break the connection
between these two.

00:58:17.640 --> 00:58:18.140
And there we go.

00:58:18.140 --> 00:58:18.950
We've broken our joint.

00:58:21.270 --> 00:58:23.100
So we have a fixed
joint between these two

00:58:23.100 --> 00:58:24.790
objects that can
break with a force.

00:58:24.790 --> 00:58:27.470
This is awesome for scenes where
you have drop in objects, and

00:58:27.470 --> 00:58:30.700
you need to break through boards
and boxes and things like that.

00:58:30.700 --> 00:58:32.410
You just make your boxes.

00:58:32.410 --> 00:58:34.440
Were connected by
fixed joints here.

00:58:34.440 --> 00:58:36.090
So let's run this at full speed,
see what this looks like.

00:58:38.490 --> 00:58:38.990
Perfect.

00:58:40.310 --> 00:58:43.080
And now because they
didn't have gravity,

00:58:43.080 --> 00:58:45.540
they're acting like they
were in outer space and

00:58:45.540 --> 00:58:49.450
it's basically as if this was
a meteor coming to hit them, and

00:58:49.450 --> 00:58:50.940
notice they're not
following the gravity,

00:58:50.940 --> 00:58:53.050
they're just kinda more
rotating from that force.

00:58:53.050 --> 00:58:58.250
This is actually how
things act in space. Cool.

00:58:58.250 --> 00:58:59.030
All right.

00:58:59.030 --> 00:59:01.320
Hopefully you can see what
you can do with some joints.

00:59:01.320 --> 00:59:03.170
They're pretty simple to setup.

00:59:03.170 --> 00:59:05.830
There's a whole set for
2D ones as well.

00:59:05.830 --> 00:59:07.239
I just wanna get you
started with joints.

00:59:09.240 --> 00:59:10.470
All right, so that's a wrap.

00:59:10.470 --> 00:59:12.360
We've got module one done and
module two,

00:59:12.360 --> 00:59:13.630
both introduction to physics.

00:59:13.630 --> 00:59:15.150
Indubitably, you can see that
we've got a lot of different

00:59:15.150 --> 00:59:16.730
subjects to cover there.

00:59:16.730 --> 00:59:18.070
Hopefully, you got
a lot out of this,

00:59:18.070 --> 00:59:21.490
and let me know of any subjects
you wanna see in the future.

00:59:21.490 --> 00:59:23.980
I've provided some links
up here, some URLs for

00:59:23.980 --> 00:59:25.280
you to check out.

00:59:25.280 --> 00:59:27.520
Make sure you check out
Adam Tuliper.com and

00:59:27.520 --> 00:59:30.860
my channel 0 video blog, Adam's
Garage, and of course make sure

00:59:30.860 --> 00:59:33.810
you check out future and past
episodes of the Game Dev show.

00:59:33.810 --> 00:59:37.601
Guys, thank you so much and
we will see you online soon.

00:59:37.601 --> 00:59:45.811
[MUSIC]

