Game Development Reference
In-Depth Information
10. Add the script to get the movement direcion of the enemy and check for the
jumping behavior as follows:
//If the target direction is not zero - means there is no
button pressing
if (v3_targetDirection != Vector3.zero) {
//Rotate toward the target direction
v3_moveDirection = Vector3.Slerp(v3_moveDirection, v3_
targetDirection, f_rotateSpeed * Time.deltaTime);
//Get only direction by normalize our target vector
v3_moveDirection = v3_moveDirection.normalized;
} else {
v3_moveDirection = Vector3.zero;
}
//Checking if character is on the ground
if (!b_isJumping) {
//Holding Shift to run
if (b_isRun) {
f_moveSpeed = runSpeed;
} else {
b_isRun = false;
f_moveSpeed = walkSpeed;
}
//Press Space to Jump
if (Jump(v3_moveDirection)) {
b_isJumping = true;
f_verticalSpeed = jumpSpeed;
}
}
11. Now we can add gravity checking, get the actual movement direcion, and apply the
animaion clip as we did in the CharacterControl script in Project 4 , The Hero/
Heroine Part II - Animaion and Controls . Let's add the script as follows:
// Apply gravity
if (IsGrounded()) {
f_verticalSpeed = 0.0; //if our character is grounded
b_isJumping = false; //Checking if our character is in the
air or not
f_inAirTime = 0.0;
f_inAirStartTime = Time.time;
} else {
f_verticalSpeed -= gravity * Time.deltaTime; //if our
character in the air
//Count Time
 
Search WWH ::




Custom Search