public void CheckPlayerControls() { // Require focus if (RequireGameFocus && Application.isEditor && !Application.isFocused) { return; } // Player Up / Down if (AllowUpDownControls) { if (PlayerUpAction != null && PlayerUpAction.action.ReadValue <float>() == 1) { player.ElevateCameraHeight = Mathf.Clamp(player.ElevateCameraHeight + Time.deltaTime, 0.2f, 5f); } else if (PlayerDownAction != null && PlayerDownAction.action.ReadValue <float>() == 1) { player.ElevateCameraHeight = Mathf.Clamp(player.ElevateCameraHeight - Time.deltaTime, 0.2f, 5f); } } // Force Forward Arrow if (ForceStraightTeleportRotation && playerTeleport != null && playerTeleport.ForceStraightArrow == false) { playerTeleport.ForceStraightArrow = true; } // Player Move Forward / Back, Snap Turn if (smoothLocomotion != null && smoothLocomotion.enabled == false) { // Manually allow player movement if the smooth locomotion component is disabled smoothLocomotion.CheckControllerReferences(); smoothLocomotion.UpdateInputs(); if (smoothLocomotion.ControllerType == PlayerControllerType.CharacterController) { smoothLocomotion.MoveCharacter(); } else if (smoothLocomotion.ControllerType == PlayerControllerType.Rigidbody) { smoothLocomotion.MoveRigidCharacter(); } } }
protected virtual void checkClimbing() { GrippingClimbable = GrippingAtLeastOneClimbable(); // Check events if (GrippingClimbable && !wasGrippingClimbable) { onGrabbedClimbable(); } if (wasGrippingClimbable && !GrippingClimbable) { onReleasedClimbable(); } if (GrippingClimbable) { moveDirection = Vector3.zero; int count = 0; float length = climbers.Count; for (int i = 0; i < length; i++) { Grabber climber = climbers[i]; if (climber != null && climber.HoldingItem) { // Add hand offsets if (climber.HandSide == ControllerHand.Left) { controllerMoveAmount = previousLeftControllerPosition - LeftControllerTransform.position; } else { controllerMoveAmount = previousRightControllerPosition - RightControllerTransform.position; } // Always use last grabbed hand if (count == length - 1) { moveDirection = controllerMoveAmount; // Check if Climbable object moved position moveDirection -= climber.PreviousPosition - climber.DummyTransform.position;; } count++; } } // Apply movement to player if (smoothLocomotion) { if (smoothLocomotion.ControllerType == PlayerControllerType.CharacterController) { smoothLocomotion.MoveCharacter(moveDirection); } else if (smoothLocomotion.ControllerType == PlayerControllerType.Rigidbody) { smoothLocomotion.MoveRigidCharacter(moveDirection); // Rigidbody rigid = smoothLocomotion.GetComponent<Rigidbody>(); // rigid.velocity = Vector3.MoveTowards(rigid.velocity, (moveDirection * 5000f) * Time.fixedDeltaTime, 1f); } } else if (characterController) { characterController.Move(moveDirection); } } // Update any climber previous position for (int x = 0; x < climbers.Count; x++) { Grabber climber = climbers[x]; if (climber != null && climber.HoldingItem) { if (climber.DummyTransform != null) { // Use climber position if possible climber.PreviousPosition = climber.DummyTransform.position; } else { climber.PreviousPosition = climber.transform.position; } } } wasGrippingClimbable = GrippingClimbable; }