Game Development Reference
In-Depth Information
•
Face Before Move Angle
: This specifies how much of an angle the charac-
ter needs to be facing its target before moving. This prevents weird move-
ments with very close targets.
•
Step Up Height
: This specifies how much the character can step up; this is
used to customize behavior for things such as steep terrain and staircases.
We will discuss step up heights more in
Chapter 11
,
Advanced NavMesh
Generation
.
We use the motor system from a
Custom Action
option in our demo, but you can
use motors to move the character from any component.
Here's a little snippet that shows how to move from a standard Unity character script:
AIRigaiRig = GetComponentInChildren<AIRig>();
…
aiRig.AI.Motor.UpdateMotionTransforms();
aiRig.AI.Motor.MoveTarget.VectorTarget =
targetPositon;
aiRig.AI.Motor.Move();
aiRig.AI.Motor.ApplyMotionTransforms();
First,weget
AIRig
attachedtothecharacter.Then,wecall
UpdateMotionTrans-
forms()
to make sure that the AI system has the latest transforms (position and ro-
tation) from the character before updating. Next, we set
VectorTarget
to a
Vect-
or3
variable as
targetPosition
, so the AI system knows where we want to go.
Then, we call
Move()
to update the character's transforms in the AI system, and fi-
nally, we call
ApplyMotionTransforms()
to update our game to show the new
transforms from the AI system. Using these methods, we can update game charac-
ters at any time.
Withcustomizedmovements,wecanhaveourcharactersadaptinanywaywewant.
The best way to see how this works is to look at a demo. The demo that we will
Activities
. We will have a ship in a level searching for gold pieces, but we'll extend
it to make the gold pieces appear more random and dynamic in the level over time.
Then, we will have a bomb with a timer and when it goes off all of ships will be des-