Game Development Reference
In-Depth Information
7. Then, go down one step and click on the Main Camera object in the Hierarchy view;
go to its Inspector view. In the Mouse Look (Script) component, click on the circle
icon at the right of Script and choose MouseLook_JS as we did earlier.
Now, click Play to see the result. You will be able to control your character's moves; run by
holding the Shift key and jump by pressing the space bar. However, pressing the E key will
stop our character's movements because we didn't set up the aiming and shoot animaion in
our script yet. We will do this in the next secion.
Objective Complete - Mini Debriefing
We just created our New3PSController.js script by using the old built-in
FPSInputController.js script as the base script. We also added the new code secion to
control the animaion of the character while it is moving, running, or idle. Then, we limited
the movement and rotaion of the camera by applying the character movement direcion to
Character Motor and the Main Camera .
Then, in the Update() funcion, we added the new secion of the code to control the
animaion of our character. At irst, we check whether or not the user has pressed E :
F If the user presses it, we want the character to stop moving and play the shooing
animaion to prepare the character to be able to ire. We also set the maximum and
minimum of the camera rotaion on the Y-axis, which limits the camera to rotate
up and down only. Then, we set the motor.inputMoveDirection to Vector3.
zero because we don't want our character to move while he/she is execuing the
shooing acion.
F On the other hand, if the user doesn't press E , we check for the user input. If the
user presses the right arrow or left arrow, we change the speed to run speed; if
not we set it to walk speed. Then, we applied the movement speed to motor.
movement.maxForwardSpeed , motor.movement.maxSidewaysSpeed , and
motor.movement.maxBackwardsSpeed .
Next, we checked the character movement direcion to play the run animaion, walk
animaion, or idle animaion (we can also have the jump animaion in here, but in this
example we don't have the jump animaion, so we just leave it).
At last, we applied the movement direcion and jump to the character motor for the user
to be able to control the movement of this character, and we are done with this step. In the
next step, we will add the shoot animaion and funcion, ire script, rocket launcher, and
scope target to our character.
 
Search WWH ::




Custom Search