Game Development Reference
In-Depth Information
Adding the character script
Let's build the second half of our character system—the script that communicates
the speed value to the FSM. We need to do this so that our characters can respond
to the user's input.
1. Open the PlayerControl.cs script we wrote earlier for character motion.
2. We will use the movespeed variable as an approximation of the speed for
the speed parameter. Around line 65, after this is calculated, we will pass
the calculated speed to the animator component in the speed parameter.
Don't forget to drag-and-drop the animator component on the character to
the animator variable of the script as shown in the following code:
if (_animator)
_animator.SetFloat("speed",movespeed);
Create a new, empty GameObject named rotNode . Assign it as a child to
Player1 and give it a local position of ( 0 , -1 , 0 ) and a local rotation of (0,
180, 0).
3. Attach the Justin model instance to the player class that we have already
developed so far. Set its relative position to (0, -2, 0). Also, disable the mesh
renderer component of Player1 and its hat; we won't be needing these any-
more since we will be using the Justin model.
4. Create a public animator reference inside PlayerControls.cs . Drag-and-
drop the Justin instance to this variable so that it finds the animator compon-
ent that has been attached there.
5. Make sure that the Idle animation has the XZ and Y rotation baked into the
animation. This way, when the character is idle, its feet will not slide when the
root motion is disabled.
Search WWH ::




Custom Search