Game Development Reference
In-Depth Information
move node to 3 . Then slow down the animation a little by going back to the Anima-
tion tab and setting the Speed field to 0.75 . If you run the demo now, the animation
is a bit better. But when Penelope gets to the end of the route, the run animation just
keeps on playing. To fix this, let's track a variable in the memory called stopped .
When it is false, the run animation will play as it does now, and when stopped is
true , an idle animation will be played instead.
The first thing you need to do to fix the animation's issues with ending is add a se-
lector node as the new root. Remember, the selector node is used for the if / else
logic, so we'll use it to switch between its running state and playing an idle anim-
ation. Add a constraint node under selector and rename it to is stopped . Set
Constraint to stopped == false . Then add a new animate node under the selector
node, name it animate idle , and set Animation State to idle . This will only start
running when stopped is true, so we need to add an expression node to run the
expression node after our moving is done. Make a new sequencer node and make
it the parent of waypointpatrol . Then add an expression node under the sequencer
node with an Expression value of stopped = true .
This should look like the following screenshot:
To summarize, the selector acts as if / else using the stopped variable in the
memory, which is automatically created in the tree when we start using it. Then the
run animation is played in parallel while the character is moving, and when the mov-
ing is done, the expression sets stopped = true and the idle animation is played. If
you run the animation now, Penelope will run and then switch to idle at the end of
the path.
However, there is one problem: the transition from the running to the idle state is
very abrupt. If you run the demo, you'll easily notice a visual jump from the running
to the idle state for Penelope at the end of the path. To help with this, you can adjust
Search WWH ::




Custom Search