Game Development Reference
In-Depth Information
}
// C# user:
void Update () {
} else {
_moveDirection = Vector3.zero;
}
if (IsGrounded) {
_isJumping = false;
_verticalSpeed = 0.0f;
_inAirTime = 0.0f;
_inAirStartTime = Time.time;
} else {
_verticalSpeed -= GRAVITY * Time.deltaTime;
_inAirTime = Time.time - _inAirStartTime;
}
}
7. Next, if our character is able to jump, we will check for the jump action and set
_verticalSpeed to jumpSpeed . We also check that if the user holds Shift ,
_isRun is set to true . Then, we set _moveSpeed depending on the charac-
ter's action (run or walk). Let's put the highlighted code as follows:
// Unity JavaScript user:
function Update () {
} else {
_verticalSpeed -= GRAVITY * Time.deltaTime;
_inAirTime = Time.time - _inAirStartTime;
}
if (!_isJumping && (_motionState ==
MOTION_STATE.GROUND)) {
_isRun = (Input.GetKey (KeyCode.LeftShift) ||
Input.GetKey (KeyCode.RightShift));
_moveSpeed = (_isRun) ? runSpeed : walkSpeed;
if (Input.GetButtonDown ("Jump")) {
Search WWH ::




Custom Search