public void unDockThePlayer(bool smoothUndock = false) { if (playerDocked) { if (smoothUndock) { targetDockPosition = previousWorldPosition; targetFocalPoint = previousFocalPoint; gameObject.GetComponent <FPEMouseLook>().enableMouseLook = false; currentDockingState = ePlayerDockingState.UNDOCKING; } else { transform.position = previousWorldPosition; gameObject.GetComponent <FPEMouseLook>().disableLookRestriction(); gameObject.GetComponent <FPEMouseLook>().LookAtPosition(transform, m_Camera.transform, previousFocalPoint); playerDocked = false; } } }
public void dockThePlayer(Transform dockTransform, Vector2 maxAngleFromFocalPoint, Vector3 focalPoint, bool smoothDock = false) { playerDocked = true; // Make a "fake" focal point to restore to, just an invisible point in front of where the player was looking prior to docking previousFocalPoint = m_Camera.transform.position + (m_Camera.transform.forward * 5.0f); previousWorldPosition = transform.position; if (smoothDock) { targetDockPosition = dockTransform.position; targetMaxAngles = maxAngleFromFocalPoint; targetFocalPoint = focalPoint; currentDockingState = ePlayerDockingState.DOCKING; } else { transform.position = dockTransform.position; gameObject.GetComponent <FPEMouseLook>().LookAtPosition(transform, m_Camera.transform, focalPoint); gameObject.GetComponent <FPEMouseLook>().enableLookRestriction(maxAngleFromFocalPoint); } }
private void Update() { RotateView(); if (playerFrozen) { } else if (playerDocked) { if (currentDockingState == ePlayerDockingState.DOCKING) { transform.position = Vector3.Lerp(transform.position, targetDockPosition, dockingLerpFactor * Time.deltaTime); gameObject.GetComponent <FPEMouseLook>().LookAtPosition(transform, m_Camera.transform, targetFocalPoint); if (Vector3.Distance(transform.position, targetDockPosition) < dockSnapDistance) { transform.position = targetDockPosition; gameObject.GetComponent <FPEMouseLook>().LookAtPosition(transform, m_Camera.transform, targetFocalPoint); gameObject.GetComponent <FPEMouseLook>().enableLookRestriction(targetMaxAngles); gameObject.GetComponent <FPEMouseLook>().enableMouseLook = true; currentDockingState = ePlayerDockingState.IDLE; } } else if (currentDockingState == ePlayerDockingState.UNDOCKING) { transform.position = Vector3.Lerp(transform.position, targetDockPosition, dockingLerpFactor * Time.deltaTime); gameObject.GetComponent <FPEMouseLook>().LookAtPosition(transform, m_Camera.transform, targetFocalPoint); if (Vector3.Distance(transform.position, targetDockPosition) < dockSnapDistance) { transform.position = targetDockPosition; gameObject.GetComponent <FPEMouseLook>().LookAtPosition(transform, m_Camera.transform, targetFocalPoint); gameObject.GetComponent <FPEMouseLook>().disableLookRestriction(); gameObject.GetComponent <FPEMouseLook>().enableMouseLook = true; currentDockingState = ePlayerDockingState.IDLE; playerDocked = false; } } } else { // Only jump if we are allowed, not already jumping, and not crouched if (jumpEnabled && !m_Jump && !isCrouching) { // Workaround for conflicting jump and menu buttons when using XBox controller. When assigned bumper is pressed when menu is open, player jumps when menu is closed. if (Time.timeScale != 0.0f && m_CharacterController.isGrounded) { m_Jump = FPEInputManager.Instance.GetButtonDown(FPEInputManager.eFPEInput.FPE_INPUT_JUMP); } } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; // Crouch based on crouch method (toggle vs. hold down) if (crouchEnabled) { if (movementEnabled) { if (crouchAsToggle) { if (FPEInputManager.Instance.GetButtonDown(FPEInputManager.eFPEInput.FPE_INPUT_CROUCH)) { if (isCrouching) { if (haveHeadRoomToStand()) { isCrouching = false; } } else { isCrouching = true; } } } else { if (FPEInputManager.Instance.GetButton(FPEInputManager.eFPEInput.FPE_INPUT_CROUCH)) { isCrouching = true; } else { if (isCrouching) { if (haveHeadRoomToStand()) { isCrouching = false; } } } } } } else { // Set it to false here in case crouching is disabled during play, and player was mid-crouch isCrouching = false; } // Crouching stuff previousCharacterHeight = controller.height; if (isCrouching) { gameObject.GetComponent <CharacterController>().height = Mathf.Lerp(gameObject.GetComponent <CharacterController>().height, crouchingHeight, 5 * Time.deltaTime); } else { gameObject.GetComponent <CharacterController>().height = Mathf.Lerp(gameObject.GetComponent <CharacterController>().height, standingHeight, 5 * Time.deltaTime); } // We move the transform to be the x/z and exactly middle of Y relative to controller height change from crouch/stand gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + (controller.height - previousCharacterHeight) / 2, gameObject.transform.position.z); // Footstep audio special case: If player moves a little, but not a "full stride", there should still be a foot step sound. And if they just stopped walking, there should also be one if (FPEInputManager.Instance.GetButtonDown(FPEInputManager.eFPEInput.FPE_INPUT_HORIZONTAL) || FPEInputManager.Instance.GetButtonDown(FPEInputManager.eFPEInput.FPE_INPUT_VERTICAL) && !movementStarted) { movementStarted = true; cumulativeStepCycleCount = 0.0f; nextStepInCycle = cumulativeStepCycleCount + stepInterval; PlayFootStepAudio(); } if (FPEInputManager.Instance.GetButtonDown(FPEInputManager.eFPEInput.FPE_INPUT_HORIZONTAL) || FPEInputManager.Instance.GetButtonDown(FPEInputManager.eFPEInput.FPE_INPUT_VERTICAL) && movementStarted) { movementStarted = false; PlayFootStepAudio(); } } }