/// <summary> /// /// </summary> /// <returns></returns> private bool CheckClimbDirection() { // no climbing object, no climbing! if (m2DClimbingObject == null) { return(false); } if (m2DClimbingObject.IsOpTopOfLeanPlatform(this) && !JCS_Input.GetKey(mClimbDownKey)) { return(false); } // when is in air, character can climb what ever if (!isGrounded()) { return(true); } JCS_ClimbMoveType keyInput = JCS_ClimbMoveType.IDLE; // process input if (JCS_Input.GetKey(this.ClimbUpKey)) { keyInput = JCS_ClimbMoveType.MOVE_UP; } else if (JCS_Input.GetKey(this.mClimbDownKey)) { keyInput = JCS_ClimbMoveType.MOVE_DOWN; } switch (keyInput) { case JCS_ClimbMoveType.IDLE: return(true); case JCS_ClimbMoveType.MOVE_UP: { if (this.transform.position.y < this.m2DClimbingObject.transform.position.y) { return(true); } } break; case JCS_ClimbMoveType.MOVE_DOWN: { if (this.transform.position.y > this.m2DClimbingObject.transform.position.y) { return(true); } } break; } return(false); }
/// <summary> /// While character are climbing. /// </summary> private void CharacterClimbing() { mJumpCount = 0; if (!mStartClimbing) { if (!mAutoClimb) { if (!GetCharacterAnimator().IsInState((int)JCS_LiveObjectState.STAND) && !GetCharacterAnimator().IsInState((int)JCS_LiveObjectState.JUMP) && !GetCharacterAnimator().IsInState((int)JCS_LiveObjectState.WALK)) { ExitClimbing(0); return; } } if (m2DClimbingObject == null) { ExitClimbing(0); return; } mStartClimbing = true; } if (CanLadder) { Ladder(); } else if (CanRope) { Rope(); } else { ExitClimbing(0); return; } // while climbing zero jump count. mJumpCount = 0; mClimbMoveType = JCS_ClimbMoveType.IDLE; if (mAutoClimb) { mClimbMoveType = mAutoClimbDirection; } else { // process input if (JCS_Input.GetKey(this.ClimbUpKey)) { mClimbMoveType = JCS_ClimbMoveType.MOVE_UP; } else if (JCS_Input.GetKey(this.mClimbDownKey)) { mClimbMoveType = JCS_ClimbMoveType.MOVE_DOWN; } else { mClimbMoveType = JCS_ClimbMoveType.IDLE; GetCharacterAnimator().StopAnimationInFrame(); } } bool climbing = false; // process velocity switch (mClimbMoveType) { case JCS_ClimbMoveType.IDLE: this.mVelocity.y = 0; break; case JCS_ClimbMoveType.MOVE_UP: this.mVelocity.y = MoveSpeed; climbing = true; break; case JCS_ClimbMoveType.MOVE_DOWN: this.mVelocity.y = -MoveSpeed; climbing = true; break; } if (climbing) { if (m2DClimbingObject == null) { ExitClimbing(0); return; } // let x axis the same as ladder x axis. Vector3 newPos = this.transform.position; newPos.x = m2DClimbingObject.transform.position.x; this.transform.position = newPos; // start the animation agian GetCharacterAnimator().PlayAnimationInFrame(); } else { if (JCS_Input.GetKey(this.JumpKey) || JCS_Input.GetKey(this.JumpKey)) { if (JCS_Input.GetKey(this.LeftKey) || JCS_Input.GetKey(this.RightKey)) { ExitClimbing(); mExitingClimbing = true; } } } if (isGrounded()) { ExitClimbing(0); } }