/// <summary> /// 处理玩家移动 /// </summary> public void PlayerMove(float deltaTime, GameEngine engine, GamePlayerInput playerInput, NCamera camera) { if (TargetActor == null || engine == null) { return; } if (engine.CurrentLevel == null) { return; } KeyMove(playerInput); MouseMove(playerInput, camera, engine); #if DEBUG GameViewportControl.debugInfos.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, "CurrentMovementType: {0} Acceleration: {1} Velocity: {2} \r\n", CurrentMovementType.ToString(), Acceleration.ToString(), Velocity.ToString())); #endif }
public void GetPlayerInput() { Vector3 inputDirections = new Vector3(Input.GetAxisRaw(GameConstants.Instance.HorizontalInput), Input.GetAxisRaw(GameConstants.Instance.JumpInput) - Input.GetAxisRaw(GameConstants.Instance.CrouchInput), Input.GetAxisRaw(GameConstants.Instance.VerticalInput) ); mInputDirections = new Vector3(Input.GetAxisRaw(GameConstants.Instance.HorizontalInput), 0, Input.GetAxisRaw(GameConstants.Instance.VerticalInput) ); if (mQEInput) { if (Input.GetKey(KeyCode.Q)) { mInputDirections.y -= 1; } if (Input.GetKey(KeyCode.E)) { mInputDirections.y += 1; } } if (inputDirections.x != 0 && mADInput) { mMovementDirection += transform.right * inputDirections.x; } if (inputDirections.y != 0 && mSpaceControlInput) { mMovementDirection += transform.up * inputDirections.y; } if (inputDirections.z != 0 && mWSInput) { mMovementDirection += transform.forward * inputDirections.z; } mMovementDirection.Normalize(); //Debug.Log("Target: " + mTargetVelocity + "Current: " + mPlayerMovementSpeed + "Change as edited range: " + mCameraDistanceDifference); module.enabled = false; if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W) && mShiftInput) { mTargetVelocity = mPlayerBoostMultiplier * mPlayerNormalSpeed; mCurrentMovementType = CurrentMovementType.Boosting; if (mCurrentMovementType != mPreviousMovementType) { mPreviousMovementType = CurrentMovementType.Boosting; mLerpTimer = 0.0f; } module.enabled = true; } else if (inputDirections.z == 1) { mTargetVelocity = mPlayerNormalSpeed; mCurrentMovementType = CurrentMovementType.Normal; if (mCurrentMovementType != mPreviousMovementType) { mPreviousMovementType = CurrentMovementType.Normal; mLerpTimer = 0.0f; } } else if (inputDirections.z == -1) { mTargetVelocity = -mPlayerNormalSpeed / 2; mCurrentMovementType = CurrentMovementType.Reverse; if (mCurrentMovementType != mPreviousMovementType) { mPreviousMovementType = CurrentMovementType.Reverse; mLerpTimer = 0.0f; } } else { mTargetVelocity = 0.0f; mCurrentMovementType = CurrentMovementType.None; if (mCurrentMovementType != mPreviousMovementType) { mPreviousMovementType = CurrentMovementType.None; mLerpTimer = 0.0f; } } if (mLerpTimer < 1.0f) { mLerpTimer += Time.deltaTime * mCameraFOVLerpSpeed; } mPlayerMovementSpeed = Mathf.Lerp(mPlayerMovementSpeed, mTargetVelocity, mLerpTimer); }