Game Development Reference
In-Depth Information
Engage Thrusters
We will start with creaing the Awake() funcion:
1. Go to the Awake() funcion to set up warpMode of the animaion, and type the
following highlighted script:
//Using Awake to set up parameters before Initialize
public function Awake() : void {
controller = GetComponent(CharacterController);
b_isRun = false;
b_isBackward = false;
b_isJumping = false;
f_moveSpeed = speed;
c_collisionFlags = CollisionFlags.CollidedBelow;
//Set warpMode for each animation clip
animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
animation[fallPoseAnimation.name].wrapMode = WrapMode.ClampForever;
animation[idleAnimation.name].wrapMode = WrapMode.Loop;
animation[runAnimation.name].wrapMode = WrapMode.Loop;
animation[walkAnimation.name].wrapMode = WrapMode.Loop;
}
2. Go back to the Update() funcion in the CharacterControl.js file between
c_collisionFlags = controller.Move(v3_movement); and if (v3_
moveDirection != Vector3.zero) near the botom line of this funcion; add
the following highlighted script:
// Move the controller
c_collisionFlags = controller.Move(v3_movement);
//Play animation
if (b_isJumping) {
if (controller.velocity.y > 0 ) {
animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
animation.CrossFade(jumpPoseAnimation.name, 0.1);
} else {
animation[fallPoseAnimation.name].speed = fallAnimationSpeed;
animation.CrossFade(fallPoseAnimation.name, 0.1);
}
} else {
if (IsAir()) { // Fall down
animation[fallPoseAnimation.name].speed = fallAnimationSpeed;
animation.CrossFade(fallPoseAnimation.name, 0.1);
} else { //Not fall down
 
Search WWH ::




Custom Search