Lumberyard Animation Editor – 4/5 – Node Logic to Stop Aiming when Running

Lumberyard Animation Editor – 4/5 – Node Logic to Stop Aiming when Running


As we continue our EMotion FX Animation Editor
series Gene Yanza continues walking you through our Physx Samples gem. Make sure you have
that enabled if you’re following along at home from the Project Configurator. In the
previous episode, you saw us add motion to our aiming Cowboy. And in this episode, we’re
going to show you how to add some node logic to turn off the aiming when your cowboy is
running. So now we have the locomotion for the character,
and the character can strafe and aim and also run. So what’s happening when the character
runs, I’m gonna show you again. I’m gonna type in 1 here in the XY Move Axis in Y and
I’m gonna turn on the run tag. So you see how the arm is aiming at the target. What
I want to do is actually turn off the aiming system while the character is running. So
we want to add some bool logic to take care of that. So what I’m gonna do is hit stop
for a second. So now I’m going to add another parameter for the XY move axis. I’m gonna
go right click create node sources parameters. And again, let’s just remove some of the parameters
here to keep it clean. I’m going to pick the xy move access. And for this one, I’m gonna
go in and do the same for this. I’m just gonna pick the aim vector 3. So I’m gonna create
just a new logic here that would help us determine if the character is moving. So what I’m gonna
do is decompose this XY move axis, and I’m gonna add a decompose node. So I’m gonna go
to create node math vector 2 decompose. So now I can drag a line from XY move axis parameter
to the vector input of the decompose node. So what I want to do is, after I decompose
values I want to take, I want to get the squares of X and the squares of Y. Essentially what
we’re building is we’re going to get the magnitude of the X Y move axis. Now we don’t have a
node that gets the length so we’re gonna actually build this manually by using individual nodes.
So I’m gonna go and right click create node math, I’m gonna pick float math one and on
the right here. I’m gonna change it to square. So I’m gonna control C gonna right click here
and paste. So now that we have these two square nodes. I’m gonna take the output here. The
vector decompose from X to X. I’m gonna connect the Y to Y. So now we have the squares of
X and squares of Y. So now what we want to do is add these two values together. I’m gonna
right click create node math, and I’m gonna pick float math 2. So I’m gonna select this
and it shows add, so that’s fine. We want to add the squares, so let’s go ahead and
draw a line from this value into here and from the float math one Y into Y. Great! So now this adds the two values together
and now what we want to do is get the square root of the of that value. And I’m gonna right
click create node math float math 1, select this node and I’m gonna pick square root.
Let’s connect nodes together. Great. So now this gets the magnitude of the XY move axis.
So now what I want to do is add a float condition node. I’m gonna right click create node logic
float condition. Let’s select this node. So what I want to do here is evaluate the length
of the XY move axis. So what I’m gonna do here is on the attributes panel on the right
under condition function I’m going to pick is greater. And if this is greater than 0.05
it will evaluate as one. And if it’s not greater than 0.05 it will evaluate as zero. And so
it will give me true if it’s greater then 0.05 and false when it’s less than 0.05. So
now that we’ve got the float condition set up, I’m gonna take the output of the float
math square root and plug that into the X value. So now this basically tells me that
if my magnitude is greater than 0.05 then I’m gonna evaluate as true, but this only
takes care of when the character is actually moving. We also want the run tag to be true
too. So I’m gonna add a parameter here, create node sources parameters and let’s just pick
run. And so what I want to do is add a bool logic node. I’m gonna right click here. Create
node goto logic and pick bool logic. So let’s just connect these values together. I’m gonna
take the float output here from the float condition node into X. And I’m going to take
the run value and plug it into here in Y. And I’m gonna select a bool logic node. So
the defaults for the bool logic node are fine. What it’s doing is saying that if this is
true, if the output of this condition is true and if run is true, then this is also true.
So what this gives me is the output is true then the cowboy will stop aiming. But what
I have to do is add a another blend node here. I’m going to right click create node blending
blend 2. And let’s take the output of the blend 2 and plug it into final node. So now
what I want to do is take the output of the bool logic and plug it into the weight of
this blend 2 node. The blend to node will allow you to blend animations together and
you’ll see how I actually build this. So what I’m gonna do is take this output of the two
link IK. Let’s drag this across here. Now let’s take the output of the 2 link IK and
drag it into pose one. So what this is saying is if my weight is zero pose one will be the
output of this blend to node. So when my weight is one, we want the character to just be running.
And so I’m just gonna take the output of locomotion. Let’s zoom out I’m gonna drag this across
the screen a little bit and I’m gonna take the output of its locomotion and plug it into
pose 2. So let’s clean this up a little bit. I’m gonna zoom out and drag this back here.
What this is doing is if my bool logic output is zero, the cowboy will be aiming, and if
the output of the bool logic is one the cowboy will be running and no longer aiming. So what
the blend to node does is allows you to blend animations when the character is in locomotion
mode and when the character’s also aiming. So if the output of bool logic is zero, then
the Cowboy will be able to be in idle mode and walk and aim. But if the output of bool
logic node is one then the cowboy will just run and will not be aiming. So that’s how
that’s essentially what I set up here. So to test this, let’s actually play the anim
graph. I’m going to double click the state machine and blend tree. Let’s zoom out and
let’s just see what’s happening here. Let’s compact this graph a little bit so you can
see what’s going on. So what I did was rearranged the graph so you can see it on the screen
and let me zoom in a little bit. And now what I’m gonna do is change some of the parameters,
and we can see what’s actually going to happen. So let’s move the character forward and let’s
have the character run. So now the character runs and the aiming system is turned off.
You’ll notice that these nodes go to gray because they’re not being evaluated. And if
I turn off this run switch, the character is aiming again. And the reason why he’s aiming
back, he’s aiming back at where the target is. So I’m just gonna reset the transform
of the character, and you’ll notice that if I click on this aim vector gizmo and drag
it in the screen, now the cowboy is aiming at the target and still walking. But if I
turn on this run tag, the cowboy will start running. Now when the Cowboy started running,
it was kind of abrupt. You’ll notice. So to fix that, I’m gonna add a smoothing node.
Let’s hit stop for a second, reset the character, and I’m gonna add a smoothing node right here.
I’m gonna go create node math and smoothing. And let’s delete this line by right clicking
remove connection and I’m gonna take the float output plug it into smoothing and drag the
results into the wait here. So the smoothing node provides this interpolation speed. Basically,
it tries to reach the input value at a certain speed. So the higher the speed is, it will
reach the input value that goes into the smoothing node faster, and if it was lower it will be
a little bit slower when trying to reach the input value. So I’m gonna kind of reduce this
so we’ll have a slower interpolation towards the input value. So if you get a input value
of 1, this lower interpolation speed will mean that the output will eventually reach
one, but slower. And if the interpolation speed was higher than it would approach the
value of one faster. So let’s just dial this back down 0.3 is good and let’s hit play again.
And I’m going to have the Cowboy walk first. I changed the Y for the XY Move Axis to one.
And I’m gonna click on the run tag. And so notice that the Cowboy’s kind of blended a
little bit more smoother into the run motion. So I’m gonna turn that off, and let’s turn
it on again. And that’s a little bit better. We also set up the logic for a run switch.
Basically, if the character is running, then turn off the aiming system and just run. And
so that gives you the basics on how to do a Cowboy aiming system, along with using locomotion
in your anim graph to have the character walk while strafing and aiming and also to just
run. I hope you like the lesson and if you have any questions again, feel free to ask
more questions in the forum. Tell us what you think and feel free to comment on the
YouTube video below. Thanks again. That just scratches the surface of the assets
you have available in the new PhysX Samples gem. Special shout out to Chris Roby, our
physics team and our Script Canvas team for helping to put all that together. As always,
continue the conversation over at our forums that forums.AWSgametech.com. Please let us
know if you’d like to have more art or animation related content, and we will quickly pull
Gene back in here. He’s itching to share more information with you guys. Stay tuned. I’m
never resting. I’m always looking to work on more content and more Lumberyard tutorials
to share with you. And we are always aiming to get new content out every Tuesday. Thank
you very much for watching and supporting. I’m John R. Diaz, and I’ll see you all in
the next Lumberyard video tutorial.

Only registered users can comment.

  1. Спасибо за урок! Вы лучшие! В будущих уроках вы сможете рассказать о том как запрограммировать это через скрипт канвас?

Leave a Reply

Your email address will not be published. Required fields are marked *