Загрузка данных
Introduction to dynamic IK animation system
0:00
Hello. In this video, we're going to go
0:02
over how to create a dynamic IK
0:05
animation system so we can make it so
0:07
when the player character is playing a
0:09
certain animation, they're going to move
0:10
their hand to wherever my red ball is.
0:13
So, if my red ball's in the center, my
0:15
player character will move their hand to
0:17
the center. If I move this red ball
0:18
slightly higher, when my player
0:20
character plays this animation, they're
0:21
going to move their hand slightly
0:22
higher, and so on. So, this can be
0:26
helpful if you want your character's
0:28
bones to move to specific locations
0:30
during animations. So, maybe you want to
0:33
set this up with an interaction system,
0:35
or maybe you'll make it so your player
0:36
character's bones go to a specific
0:38
location when they're holding an object,
0:40
and so on. In this video, I'm going to
0:42
show you how you can set this up. And
0:44
before we get started, if you'd like to
0:46
learn even more about Unreal Engine,
0:47
make sure to enroll in my free Unreal
0:49
Engine beginner course. You can find a
0:51
link to that in the description of the
0:53
video. With that being said, let's get
0:55
into it. To get started, we are first
0:57
going to import an animation of the
Importing button press animation and creating montage
0:59
character pressing the button. So, I'm
1:02
just going to go over to my characters
1:03
folder, mannequins, and over to the
1:05
animations folder and over to the
1:07
unarmed folder. And attach somewhere in
1:09
the description of this video, there's
1:11
going to be a link to an animation of a
1:13
character pressing down a button. Just
1:15
import this animation if you want to
1:17
follow along with what I'm doing.
1:19
Although, this process works with any
1:20
animation. So, I'm just going to import
1:23
this animation to my project. I'm going
1:24
to scroll down and for the skeleton,
1:27
select the SK mannequin because this
1:28
animation is rigged to my Unreal Engine
1:31
mannequin character.
1:33
Next, we just want to right click on
1:35
this animation and go create and create
1:37
an animation montage. Then, we just want
Adding and configuring animation curves for IK control
1:40
to double click and open it up. Next, we
1:43
are going to add a curve to our
1:44
animation. So to do that, we just want
1:46
to go here where it says curves and go
1:48
add curve and go create curve. For the
1:51
curve name, just call it press button.
1:55
Then we just want to double click and
1:57
head inside the curve.
1:59
If you press control and zoom in and out
2:02
with your mouse wheel, that will allow
2:03
you to kind of zoom in and out. Next, we
2:07
just want to go to the start of this
2:09
animation and right click and go add
2:12
key. We want to add a key at second zero
2:16
with a value of zero at the start of our
2:18
animation.
2:20
Then I'm just going to play this
2:23
around
2:26
here where my player character is
2:28
beginning to press the button. At this
2:30
point, we're going to dynamically make
2:32
it so our character's hand will move to
2:34
wherever the button is. So at this
2:36
point, I'm just going to select my
2:38
curve, right click, and go add key.
2:41
and at second 1.3. I want this to have a
2:44
value of one.
2:46
Let me just zoom out.
2:50
And then all the way to around here. I'm
2:53
going to right click on my curve again.
2:54
Add another key
2:57
at second 3.4. I want this to have a
2:59
value of one. And then let me go all the
3:01
way to the end of my animation. So I'll
3:03
just play it.
3:06
At the end, I just want to right click
3:07
on my curve, add a key, and at the last
3:10
second, I want this to have a value of
3:12
zero.
3:14
Then, to make my curve a bit smoother,
3:16
I'm just going to select this first
3:17
point, right click, and go auto. And
3:20
then, select this third point, right
3:22
click, and select auto. And that'll just
3:25
make it so our curve is smoother. So,
3:27
when our curve is at zero, we're just
3:29
going to make it play our normal
3:30
animation. Although when our curve is at
3:33
a value of one, we're going to make it
3:35
so our player character's hand will move
3:37
to wherever we want it to. In this case,
3:40
we'll make it move towards a button that
3:41
we want our player character to press.
3:44
Next, I'm just going to minimize this
3:46
and I'm going to go over to my third
Creating button actor blueprint with sphere component
3:48
person folder, over to the blueprints
3:50
folder, and I'm just going to right
3:51
click, go over to blueprint class,
3:54
select an actor, and I'm going to call
3:55
this the bp
3:58
button.
4:01
I'm going to double click and open this
4:02
up. Go over to components, go add, and
4:06
I'm just going to select a sphere. And
4:08
I'm going to make it red.
4:13
I'm also just going to click this scale
4:15
button and make it 0.1. So, it's a lot
4:19
smaller. I will go compile. And I'm just
4:23
going to place this somewhere in my
4:24
level.
4:27
Next, I'm just going to go over to my
4:28
third person character, add in some free
Setting up input handling to play animation montage
4:31
space, I'm just going to right click and
4:33
look for the one key.
4:35
And when I press one, I'm going to drag
4:37
off here and look for play and then
4:39
montage.
4:40
And I want to play the touch button
4:44
montage that I just made. So, the next
4:46
thing we want to do is we want to make
4:48
it so when the player presses the one
4:49
button,
4:51
they're going to move their hand to
4:52
wherever my button is. To do that, we
Getting curve value in animation blueprint
4:56
want to just open up our character's
4:57
animation blueprint. So, let me go over
5:00
to mannequins, animations, unarmed, and
5:03
then over to the animation blueprint,
5:05
unarmed.
5:06
And we just want to go over to the event
5:08
graph. And then we just want to add a
5:10
pin here. So, we're going to be adding
5:12
this to the event blueprint update
5:14
animation. So, this will run whenever we
5:16
are basically updating our character's
5:18
animations.
5:20
And what we want to do is we just want
5:21
to right click and look for get curve
5:24
value.
5:26
So we want to get the value of whatever
5:28
we called our curve. So just get what
5:30
you called it. So I called mine press
5:31
button. And you want to make sure that
5:33
it's spelled the same here. So I'm just
5:35
going to type this in. Press button.
5:38
And we just want to keep track of this.
5:40
So right click on this and go promote to
5:42
variable. And we can just call this the
5:44
curve value.
5:50
We can then connect from then into here.
5:54
Next, we just want to right click and
5:56
look for get player character. This will
5:59
allow me to reference the player
6:01
character that I'm playing my game as.
6:02
I'm in the third person template, so
6:04
that's going to be the third person
6:05
character. So, I'm just going to cast to
6:08
the third person character. Connect from
6:10
here into here. And then inside of my
6:13
third person character,
6:15
I want to basically get the location of
6:17
where the ball is in my level. So into
6:21
free space, I'm just going to right
6:22
click and look for event picking play.
Getting target location from button actor in world
6:25
And event pick and play. I'm going to
6:27
drag off here and look for get actor of
6:30
class.
6:32
And that is going to be the bp button.
6:38
I want to drag off here and look for get
6:40
actor location.
6:42
And then I'm going to right click here
6:43
and permit this to a variable. And we
6:45
can call this the target location.
6:50
This is going to be the location of
6:51
where we want our player character's
6:53
hand to go. We can just compile this. Go
6:57
back to our animation blueprint unarmed.
6:59
And I'm going to get the target location
7:04
variable. And I'm just going to right
7:06
click here and promote it to a variable
7:08
called target location inside of my
7:10
animation blueprint. I will then connect
7:12
from here to here.
7:15
And I can just comment this
7:20
update
7:21
curve value and target location.
7:27
Next, we just want to go over to the
7:28
animation graph.
Setting up CCDIK node in animation graph
7:35
and move the output pose further here.
7:38
Then we just want to right click and
7:40
look for the CC dick node and connect
7:44
from here into component pose and from
7:46
here into the result and connect from
7:49
the curve value into here
7:53
and from the target location into here.
7:57
So whenever our curve has a value of
7:59
one, it's going to make a specific bone
8:01
that we can specify on our character
8:04
move towards this target location. So
8:07
let's set that up. We just want to
8:08
select the CC dick node and scroll down.
8:12
Go over to solver and we want to go over
8:14
to tip bone. This is going to be the
8:16
bone that moves towards the target
8:19
location. So for me, I just want to
8:21
select my character's handbone.
8:24
We then want the root bone. This is
8:26
going to be the bone at which it limits
8:29
the movement. So, it's not going to move
8:32
my characters. So, it's not going to
8:34
move beyond the root bone. For the root
8:36
bone, I just want to select my clavicle
8:40
R. If we just go over to the SK
8:42
mannequin skeleton, we can see those
8:45
bones.
8:47
So, the clavicle R is this bone
8:51
and the hand R bone is this bone. So
8:54
this is the bone where it will start and
8:56
the clavicle bone is going to be the
8:57
bone where it ends. Next we just want to
9:00
select this node and very important we
9:02
just want to go to aector location
9:04
space. So we just want to change this to
9:07
world space. So it's going to move our
9:10
hand rone to where the target location
9:13
is in the world space. If this is set to
9:15
component space then then it's going to
9:17
do this relative to where the skeleton's
9:19
bones are. So we want to change this to
9:21
world space.
9:23
Then if I just go compile, save this,
Testing the system and enabling rotation limits
9:27
minimize this,
9:29
and let me just place this here.
9:33
I'll save everything. And then let me
9:35
play my game. Let me go up to this
9:36
button. And if I press one, we can see
9:39
my character's hand is going to move to
9:41
where this is. If say I move here and
9:44
then I press one, we can see my
9:46
character's handbone is still moving to
9:48
where that button is despite the fact
9:51
that I've moved to a slightly different
9:53
place. If say I go here, then I press
9:55
one, the same thing. So that can be
9:59
super helpful if you want to create
10:00
dynamic animations. Also, just to note
10:04
with this system, if say I turn around
10:07
and then I press one, then my
10:09
character's hand will kind of like go
10:11
through itself. If you want to prevent
10:13
that, just open up your character's
10:14
animation blueprint. And for the CC dick
10:18
node, just enable this, enable rotation
10:20
limit, and compile this. And that'll
10:23
just make it so the bone can only really
10:25
move within its rotation limit and range
10:29
and bound. That's all for this video. If
Conclusion and additional resources
10:31
you want to learn even more about Unreal
10:33
Engine's animation system, make sure to
10:35
check out my Unreal Engine fundamental
10:37
course. You can find a link to that in
10:38
the description of the video. If you
10:40
enjoyed, make sure to like and
10:41
subscribe. And I'll see you guys in the
10:42
next one. Bye.