♪♪♪
(Wes Bunn) Okay, so we are back. In the previous video, we finished setting up our punching
Animation Montage allowing our Character to run around and punch in our level here. So
if we Play in the editor again, I can punch once. I can hold down the Left Mouse Button (LMB)
and punch multiple times. I can also run around and punch, or jump and punch. So,
our Character is somewhat playable now. The last thing that I wanted to do is allow our
Character to kind of interact with our world a little bit. So let's go ahead and do that.
I am going to hit Esc to exit my play session here. Down inside the Content Browser, what
we are going to do is go to the Character folder. We are going to go to our Character
Blueprint (CharacterBP) here, Double-click and open it up. Inside of our CharacterBP let's
hop over to our viewport. So we are going to go to the Viewport tab up here so that
we can see our Character. What we need to do is add some collision somewhere around
his hands for when his hands punch outside of our CollisionCapsule here, which is used
for our general collision to make sure that our Character can't pass through things. But
when his arms extend out past our CollisionCapsule, we want to add collision around his hands
so that he can interact with the world. So we are going to do that kind of in a cheap
way here, but it should get the job done. So to do that, let's go up to the Components
window and let's click Add Component. Let's search for a Sphere Component. There are two
options here. We want to use the Sphere Collision, so go ahead and select that. Let's call this
the "RightHandCollision", like so. Let's add another one. Let's add another Component:
Sphere. Let's just add another Sphere Collision. We will call this one "LeftHandCollision",
like so. Now let's select both of these. You hold Shift and select both of these. Over in
the Details panel on the right under Collision, there is a Collision Presets section which
allows you to set the Collision Presets and how collision is used for these objects. Currently
they are set to OverlapAllDynamic, which doesn't really hurt anything. But we are going to
actually change this to NoCollision because we are going to turn collision on for these
when the Character is punching and only when the Character is punching. So with that, I
think we are good in terms of setting up their properties. Let's go over to our RightHandCollision
now. Let's actually move that into position on his right hand. So we are going to move
that over just a little bit, like so. Let's actually do one more thing. Let's go up to
the top up here and let's change our position Grid Snap Value. Let's change this down to
1 so that we can move it more freely. Now it doesn't have to be precise where we place
this because we are actually going to attach this to the Character's hand when he is punching.
I am just kind of putting it close to his hand just for clarity on where it should be.
So somewhere like this, and then also I am going to hit R to go into Scale Mode.
Grab this white box in the center here and just drag it to the right to kind of scale it down
a little bit, something like that. Let's hit W and move it back towards his hand a little
bit better. And down, something like that. That looks good. So we are going to do the
same thing for the other side. I am going to grab my LeftHandCollision. I am going to
move it over to my left hand. I am going to scale it down by hitting R, and grabbing my
white box here and dragging it to the right. You could also do this with the Sphere Radius
if you wanted to change the size of the sphere as well. But I think this will do just fine.
Hit W to go to Translation Mode and move it up towards his hand, something like this.
Something like that. He is idling, so he is moving in and out of it. But again, we are
going to attach these so I think that is good. This one is a little bit smaller than that
one. (Laughter) But, I think that is good. Let's Compile and Save. What we need to do
now is hop to our Construction Script. Now, we haven't used the Construction Script yet.
But essentially what the Construction Script does is any time that this Blueprint is constructed,
as the name suggests, it is going to fire whatever is connected to this wire. Now when
we say constructed, that means inside the play session or inside the editor. So any
time any changes are made to this Blueprint inside the Level Editor, the Construction
Script here will fire as well. So just kind of a quick kind of brief on what the Construction
Script does. So what we need to do is grab our two collision spheres here. We can do
that by going to the My Blueprint window under Components. There are our two collision spheres.
So let's hold Ctrl and drag in our LeftHandCollision Sphere Component. Hold Ctrl and drag in our
RightHandCollision. What we need to do is attach these now. So to do this, let's drag
off of our LeftHandCollision and say, "Attach to". That gives us two options: Attach to
and Attach Actor to Component. We want the actual "Attach to", so let's go ahead and
select AttachTo. Let's move this one (Right Hand Collision) down just a little bit. It
is going to say what is the Parent? What is the thing that we are attaching to? We are
actually going to attach this to our Mesh. So to get that, we need to go back to our
My Blueprint panel. It is not shown by default, but what we can do is go up to the View Options
here. Click this option and we can Show Inherited Variables. So go ahead and select that. When you do,
everything that is inherited is also shown in here. So underneath Character, there is
our Mesh. So we can hold Ctrl and drag that in. Actually, I don't know if you need to
hold Ctrl. Let me just check that really quickly for my own personal...yeah, I guess you do.
It is still going to give us a Getter. Hold Ctrl and drag it (Mesh) in and then connect
that as the Parent, so the In Parent. It is asking for a Socket Name. Now we can use a
bone name as well. We are not going to be able to see that inside the viewport here.
But really quickly if you need to know the bone name that you want to attach it to, we
can do that by going to our CharacterAnimBP for example. Go to the Skeleton tab or any tab
that has the Skeleton Tree in it. We can see the name of our hand. So it is hand_r where
we are going to attach it. Where is our other hand? Somewhere around here. "hand_l" for our
left hand. So those are the two names that we need to use. So inside our CharacterBP
again, the Socket Name we want to use for our left hand is "hand_l". The Attach Type
is the method that we want to use to attach it. We are going to snap to the Target
so it will snap the Collision Sphere Component directly to that location. So go
ahead and "Snap to Target, Keep World Scale". We want to keep our scale; we don't want to
change it because we have already set it. Then, everything else is good; I think we
are done. We can connect our Construction Script now to our AttachTo. Then, let's
copy this node. Let's Ctrl + C and Ctrl + V. Connect these together, like so. Let's grab
our Mesh here and connect that as the In Parent. Let's grab our RightHandCollision now and
connect that as the Target. Now we do need to change our Socket Name, so change this
to "hand_r". So let's change that to "hand_r". Let's Compile. You can see it fires and has
been updated. The last thing we need to do for our CharacterBP here is to turn on our
collision when we are punching. This should be pretty easy. We can hop over to our Event Graph
to do that. So let's go to the Event Graph. Find our Punching script here and let's go
get our LeftHandCollision. So hold Ctrl and drag that in. Hold Ctrl and drag in our RightHandCollision.
What we want to do is drag off of the LeftHandCollision and say, "Set Collision Enabled". That is
the one that we want. So go ahead and select that Set Collision Enabled. Once that is selected,
connect the Set here off the "IsPunching?" to our Set Collision Enabled, like so. We
can connect our RightHandCollision as well. Let's connect that to the Target, like so.
The type of collision that we want to apply... We don't want to apply No Collision. We actually
want Collision Enabled. So from the drop down, change that to Collision Enabled. So whenever
we are punching, set Collision Enabled for our two Collision Sphere Components here.
The last bit of business that we need to do is select our node, hit Ctrl + C to copy it,
and Ctrl + V to paste it. Let's connect our "IsPunching?" false and Set our Collision
Type to No Collision, like so. Then, let's connect our LeftHandCollision to the Target
and our RightHandCollision to the Target as well. So let me select these two nodes and
just move them up here for a little bit of clarity, like so. Expand our comment section.
There we go. So we are done. We are done setting up our Punching. Let's Compile and Save up
here at the top. So Compile and Save. The last thing that we are going to do is let's
hop back to our level here. Let's add something in here that we can actually interact with.
So I am going to use starter content for this. I am going to go down to the Starter Content
folder under Props. Let's not go to Props, let's go to Shapes. So, the Shapes folder
here. Let's just grab our Shape_Sphere and drag that into our level like that. Where
is our Character? There he is. Let's make it a little bit bigger. I am going to hit
R, then grab our white box in the middle here, and drag it to the left to kind of scale it up.
Then over in the Details panel, we need to find the Physics section. We want to set
this to Simulate Physics. So go ahead and turn that on. With that, we should be able
to go over to it and punch it now. So let's test this and see. So we will Play in the
editor here. Now whenever we punch, our collision should be enabled and we should be able to
punch our little Sphere way off of our level like so. (Laughter) That was beautiful. So
that's it. We are done. Our Character can now punch things. Had these things been physics
objects, we probably could punch them too. We are going to wrap here for this video.
In the next video, we are going to set up our Particle Effects so that when we are running
we can kick up some dust to kind of use our Animation Notifies and a Particle Effect.
So we will wrap here and in the next video we will set up that Particle Effect for when
we are running. Thank you guys for tuning in and we will see you in the next video.
♪♪♪