// Go out of wall climbing mode public void DeactivateWallClimbing() { //transform.parent = null; m_currentState = ClimbingState.ReleasedWall; m_controllerWallClimbing.enabled = false; m_controllerPlayer.DeactivateClimbing(); }
// Go out of ledge climbing mode public void DeactivateLedgeClimbing() { m_currentState = ClimbingState.ReleasedLedge; transform.parent = null; m_controllerLedgeClimbing.enabled = false; m_controllerPlayer.DeactivateClimbing(); }
private void MoveToClimbingPoint() { ClimbingState cState = _climbHandler.CurrentClimbingState; MovementState.UpdatePivot = cState.Climb != Climb.Prep && MovementState.CharacterPoint != ColliderPoint.Centre; bool applyRotation = Anim.GetBool(PlayerAnimBool.Corner) && MovementState.CharacterPoint == ColliderPoint.Centre; if (cState.Climb == Climb.Down && _movement.IsCollidingWithNonPivot(true)) { CancelClimbingState(); CancelAnimation(); } else if (_movement.MoveLinearly(cState.MovementSpeed, applyRotation, _isHopping) == false) { if (_climbHandler.CheckReattach()) { _movement.MoveLinearly(cState.MovementSpeed, applyRotation); } else { CancelClimbingState(); CancelAnimation(); } } }
static public ClimbingState GetInstance() { if (instance == null) { instance = new ClimbingState(); } return(instance); }
// Al interactuar con la Rope (Soga), se cambia el estado a Climbing, se resetean las animaciones // poniendo los principales bool del animatorController en false, se pone el animatorController // para que muestre la animacion de Climbing, y se cambiar el rigidBody a Kinematic // para que deje de ser afectado por la gravedad public override void Interact(PlayerInteraction pi, PlayerMovement pm) { pm.SwapState(ClimbingState.GetInstance()); pi.ResetAnims(); pi.anim.SetBool("isClimbing", true); pm.rBody.isKinematic = true; pi.SetWeaponActive(false); }
//private void CheckForClimbingAreas() //{ // //if ((GetState().Equals(MovementState.Jumping) || GetState().Equals(MovementState.Falling) || GetState().Equals(MovementState.WallClimbing) || GetState().Equals(MovementState.LedgeClimbing))) // //{ // Vector3 endpointR = ((transform.forward.normalized * m_climbCheckRayDist) + m_climbRaycheckR.position); // Vector3 endpointL = ((transform.forward.normalized * m_climbCheckRayDist) + m_climbRaycheckL.position); // Debug.DrawLine(m_climbRaycheckR.position, endpointR, Color.blue); // Debug.DrawLine(m_climbRaycheckL.position, endpointL, Color.blue); // // Shoot two rays forward from above head // RaycastHit hitR; // RaycastHit hitL; // if (Physics.Linecast(m_climbRaycheckR.position, endpointR, out hitR, m_climbCheckLayers) // && // Physics.Linecast(m_climbRaycheckL.position, endpointL, out hitL, m_climbCheckLayers)) // { // // Did both hit ledge trigger? // if ((hitL.collider.gameObject.tag.Equals("ClimbLedge") && hitR.collider.gameObject.tag.Equals("ClimbLedge")) && m_findLedges) // { // // Switch to // if (m_controllerPlayer.GetState().Equals(ControllerPlayer.MovementState.WallClimbing)) // { // SwitchToLedgeClimb(hitR.collider.gameObject.GetComponent<LedgeEdge>().GetClosestTarget(transform.position)); // } // // Activate // else if (!m_controllerPlayer.GetState().Equals(ControllerPlayer.MovementState.LedgeClimbing)) // { // // Start climbing at climb target closest to a point between raycasts // ActivateLedgeClimbing(hitR.collider.gameObject.GetComponent<LedgeEdge>().GetClosestTarget(transform.position)); // } // } // // Did both hit wall trigger? // else if ((hitL.collider.gameObject.tag.Equals("ClimbWall") && hitR.collider.gameObject.tag.Equals("ClimbWall")) && m_findWalls) // { // // Switch to // if (m_controllerPlayer.GetState().Equals(ControllerPlayer.MovementState.LedgeClimbing)) // { // SwitchToWallClimb(hitL.collider.gameObject.transform); // } // // Activate // else if (!m_controllerPlayer.GetState().Equals(ControllerPlayer.MovementState.WallClimbing)) // { // if (Vector3.Distance(hitL.point, m_climbRaycheckL.position) <= m_controllerWallClimbing.DistanceFromWall) // ActivateWallClimbing(hitL.collider.gameObject.transform); // } // } // } // //} //} // Go into wall climbing mode public void ActivateWallClimbing(Transform wall) { //transform.parent = wall; m_currentState = ClimbingState.WallClimbing; m_controllerWallClimbing.enabled = true; m_controllerWallClimbing.InitiateClimb(wall.rotation); m_controllerPlayer.ActivateClimbing(); }
// Go from wall climbing to ledge climbing private void SwitchToLedgeClimb(ClimbTarget initialTarget) { //print("SWITCH"); m_currentState = ClimbingState.LedgeClimbing; m_controllerWallClimbing.enabled = false; m_controllerLedgeClimbing.enabled = true; m_controllerLedgeClimbing.InitiateClimb(initialTarget); }
void Start() { m_controllerPlayer = GetComponent <ControllerPlayer>(); m_controllerWallClimbing = GetComponent <ControllerWallClimbing>(); m_controllerLedgeClimbing = GetComponent <ControllerLedgeClimbing>(); m_collider = GetComponent <CapsuleCollider>(); m_currentState = ClimbingState.NotClimbing; }
// Go into ledge climbing mode public void ActivateLedgeClimbing(ClimbTarget initialTarget) { m_currentState = ClimbingState.LedgeClimbing; transform.parent = initialTarget.transform; m_controllerLedgeClimbing.enabled = true; m_controllerLedgeClimbing.InitiateClimb(initialTarget); m_controllerPlayer.ActivateClimbing(); }
// Go from ledgeclimbing to wall climbing private void SwitchToWallClimb(Transform wall) { transform.parent = null; m_currentState = ClimbingState.WallClimbing; m_controllerLedgeClimbing.enabled = false; m_controllerWallClimbing.enabled = true; m_controllerWallClimbing.InitiateClimb(wall.rotation); }
public override void OnStateEnter(MyMovementState previousState) { KinematicCharacterMotor.HandlePhysics(false, true); _climbingState = ClimbingState.Anchoring; // Store the target position and rotation to snap to _targetPosition = ActiveLadder.ClosestPointOnLadderSegment(KinematicCharacterMotor.TransientPosition, out _onLadderSegmentState); _targetRotation = ActiveLadder.transform.rotation; }
/// <summary> /// Event when entering a state /// </summary> // // capsule while swimming // radious = 0.47 //height 1.96 //y offset 0.86 public void OnStateEnter(CharacterState state, CharacterState fromState) { switch (state) { case CharacterState.Default: { Motor.SetCapsuleDimensions(default_radius, default_height, default_y); Motor.SetGroundSolvingActivation(true); break; } case CharacterState.Swimming: { if (_Animator.GetBool("a_run")) { _Animator.SetBool("a_run", false); } _Animator.SetBool("a_wateridle", true); Motor.SetCapsuleDimensions(0.47f, 1.96f, 0.86f); Motor.SetGroundSolvingActivation(false); break; } case CharacterState.Climbing: { _rotationBeforeClimbing = Motor.TransientRotation; Motor.SetMovementCollisionsSolvingActivation(false); Motor.SetGroundSolvingActivation(false); _climbingState = ClimbingState.Anchoring; // Store the target position and rotation to snap to _ladderTargetPosition = _activeLadder.ClosestPointOnLadderSegment(Motor.TransientPosition, out _onLadderSegmentState); _ladderTargetRotation = _activeLadder.transform.rotation; _Animator.SetBool("a_climb", true); // Camera look at okayer OrbitCamera.PlanarDirection = Motor.CharacterForward; break; } case CharacterState.Weapon_Strafe: _Animator.SetBool("a_wep_strafe", true); MaxStableMoveSpeed = 2; break; } }
//RaycastHit2D[] info; public override void UpdateState(Character c, UserInput input, RaycastHit2D[] info) { this.info = info; base.UpdateState(c, input, info); //Debug.Log("Idle state updating"); c.currentLinearSpeed = input.xInput * c.maxSpeed * GameManager.Instance.DeltaTime * GameManager.Instance.DeltaTime; if (c.StateList.Count == index) { //Check if character is within the ladder's proximity //Ladder can only be climbed when the character is idle contactWithLadder = CheckLadderProximity(); //Audio c.SetSoundEffect(); //animation AnimateState(c); } //State Exit conditions if (input.xInput != 0 && c.StateList.Count == index) { //Debug.Log("Running"); //c.State = null; //c.State = new RunningState(); //Debug.Log("runnnn"); States nextState = new RunningState(); nextState.index = c.StateList.Count + 1; c.StateList.Add(nextState); } if (input.jumpPressed && c.StateList.Count == index) { //c.State = null; //c.State = new JumpingState(); States nextState = new JumpingState(); nextState.index = c.StateList.Count + 1; c.StateList.Add(nextState); } //Shifting to climbing state if (contactWithLadder && input.climbPressed && c.StateList.Count == index) { Debug.Log("climbing state initiated"); States nextState = new ClimbingState(ladder, c); nextState.index = c.StateList.Count + 1; c.StateList.Add(nextState); } }
public override void AfterCharacterUpdate(float deltaTime) { switch (_climbingState) { case ClimbingState.Climbing: // Detect getting off ladder during climbing ActiveLadder.ClosestPointOnLadderSegment(KinematicCharacterMotor.TransientPosition, out _onLadderSegmentState); if (Mathf.Abs(_onLadderSegmentState) > 0.05f) { _climbingState = ClimbingState.DeAnchoring; // If we're higher than the ladder top point if (_onLadderSegmentState > 0) { _targetPosition = ActiveLadder.TopReleasePoint.position; _targetRotation = ActiveLadder.TopReleasePoint.rotation; } // If we're lower than the ladder bottom point else if (_onLadderSegmentState < 0) { _targetPosition = ActiveLadder.BottomReleasePoint.position; _targetRotation = ActiveLadder.BottomReleasePoint.rotation; } } break; case ClimbingState.Anchoring: case ClimbingState.DeAnchoring: // Detect transitioning out from anchoring states if (_anchoringTimer >= AnchoringDuration) { if (_climbingState == ClimbingState.Anchoring) { _climbingState = ClimbingState.Climbing; } else if (_climbingState == ClimbingState.DeAnchoring) { AssignedCharacterController.TransitionToState(AssignedCharacterController.DefaultMovementState); } } // Keep track of time since we started anchoring _anchoringTimer += deltaTime; break; } }
private PlayerState SetMotorToClimbState() { Interaction.Object = null; CancelVelocity(); ClimbingState cState = _climbHandler.CurrentClimbingState; if (cState.Climb != Climb.Prep) { MovementState.SetPivotCollider(cState.PivotCollider, cState.PivotPosition, cState.PlayerPosition); } else { MovementState.JumpInPlace(); } return(PlayerState.Climbing); }
public override void OnEnable() { base.OnEnable(); state = State.Suspended; previousState = State.Suspended; climbingState = ClimbingState.Idle; previousClimbingState = ClimbingState.Idle; lastCollidingClimbingState = ClimbingState.None; clothComponents = GetComponentsInChildren <Cloth>(); ledgeGeometry = LedgeGeometry.Create(); wallGeometry = WallGeometry.Create(); ledgeAnchor = LedgeAnchor.Create(); wallAnchor = WallAnchor.Create(); transition = MemoryIdentifier.Invalid; locomotion = MemoryIdentifier.Invalid; }
/// <summary> /// Event when entering a state /// </summary> public void OnStateEnter(CharacterState state, CharacterState fromState) { switch (state) { case CharacterState.Default: { break; } case CharacterState.Climbing: { _rotationBeforeClimbing = Motor.TransientRotation; Motor.SetMovementCollisionsSolvingActivation(false); _climbingState = ClimbingState.Anchoring; // Store the target position and rotation to snap to _ladderTargetPosition = _activeLadder.ClosestPointOnLadderSegment(Motor.TransientPosition, out _onLadderSegmentState); _ladderTargetRotation = _activeLadder.transform.rotation; break; } } }
public override void OnEnable() { base.OnEnable(); kinematica = GetComponent <Kinematica>(); state = State.Suspended; previousState = State.Suspended; climbingState = ClimbingState.Idle; previousClimbingState = ClimbingState.Idle; lastCollidingClimbingState = ClimbingState.None; clothComponents = GetComponentsInChildren <Cloth>(); ledgeGeometry = LedgeGeometry.Create(); wallGeometry = WallGeometry.Create(); ledgeAnchor = LedgeAnchor.Create(); wallAnchor = WallAnchor.Create(); anchoredTransition = AnchoredTransitionTask.Invalid; }
/// <summary> /// (Called by KinematicCharacterMotor during its update cycle) /// This is called after the character has finished its movement update /// </summary> public void AfterCharacterUpdate(float deltaTime) { switch (CurrentCharacterState) { case CharacterState.Default: { // Handle jump-related values { // Handle jumping pre-ground grace period if (_jumpRequested && _timeSinceJumpRequested > JumpPreGroundingGraceTime) { _jumpRequested = false; } if (AllowJumpingWhenSliding ? Motor.GroundingStatus.FoundAnyGround : Motor.GroundingStatus.IsStableOnGround) { // If we're on a ground surface, reset jumping values if (!_jumpedThisFrame) { _doubleJumpConsumed = false; _jumpConsumed = false; } _timeSinceLastAbleToJump = 0f; } else { // Keep track of time since we were last able to jump (for grace period) _timeSinceLastAbleToJump += deltaTime; } } // Handle uncrouching if (_isCrouching && !_shouldBeCrouching) { // Do an overlap test with the character's standing height to see if there are any obstructions Motor.SetCapsuleDimensions(0.5f, 2f, 1f); if (Motor.CharacterOverlap( Motor.TransientPosition, Motor.TransientRotation, _probedColliders, Motor.CollidableLayers, QueryTriggerInteraction.Ignore) > 0) { // If obstructions, just stick to crouching dimensions Motor.SetCapsuleDimensions(0.5f, 1f, 0.5f); } else { // If no obstructions, uncrouch MeshRoot.localScale = new Vector3(1f, 1f, 1f); _isCrouching = false; } } break; } case CharacterState.Climbing: { switch (_climbingState) { case ClimbingState.Climbing: // Detect getting off ladder during climbing _activeLadder.ClosestPointOnLadderSegment(Motor.TransientPosition, out _onLadderSegmentState); if (Mathf.Abs(_onLadderSegmentState) > 0.05f) { _climbingState = ClimbingState.DeAnchoring; // If we're higher than the ladder top point if (_onLadderSegmentState > 0) { _ladderTargetPosition = _activeLadder.TopReleasePoint.position; _ladderTargetRotation = _activeLadder.TopReleasePoint.rotation; } // If we're lower than the ladder bottom point else if (_onLadderSegmentState < 0) { _ladderTargetPosition = _activeLadder.BottomReleasePoint.position; _ladderTargetRotation = _activeLadder.BottomReleasePoint.rotation; } } break; case ClimbingState.Anchoring: case ClimbingState.DeAnchoring: // Detect transitioning out from anchoring states if (_anchoringTimer >= AnchoringDuration) { if (_climbingState == ClimbingState.Anchoring) { _climbingState = ClimbingState.Climbing; } else if (_climbingState == ClimbingState.DeAnchoring) { TransitionToState(CharacterState.Default); } } // Keep track of time since we started anchoring _anchoringTimer += deltaTime; break; } break; } } }
/// <summary> /// This is called every frame by MyPlayer in order to tell the character what its inputs are /// </summary> public void SetInputs(ref PlayerCharacterInputs inputs) { // Handle ladder transitions _ladderUpDownInput = inputs.MoveAxisForward; if (inputs.ClimbLadder) { if (Motor.CharacterOverlap(Motor.TransientPosition, Motor.TransientRotation, _probedColliders, InteractionLayer, QueryTriggerInteraction.Collide) > 0) { if (_probedColliders[0] != null) { // Handle ladders MyLadder ladder = _probedColliders[0].gameObject.GetComponent <MyLadder>(); if (ladder) { // Transition to ladder climbing state if (CurrentCharacterState == CharacterState.Default) { _activeLadder = ladder; TransitionToState(CharacterState.Climbing); } // Transition back to default movement state else if (CurrentCharacterState == CharacterState.Climbing) { _climbingState = ClimbingState.DeAnchoring; _ladderTargetPosition = Motor.TransientPosition; _ladderTargetRotation = _rotationBeforeClimbing; } } } } } // Clamp input Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f); // Calculate camera direction and rotation on the character plane Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized; if (cameraPlanarDirection.sqrMagnitude == 0f) { cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized; } Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp); switch (CurrentCharacterState) { case CharacterState.Default: { // Move and look inputs _moveInputVector = cameraPlanarRotation * moveInputVector; _lookInputVector = cameraPlanarDirection; // Jumping input if (inputs.JumpDown) { _timeSinceJumpRequested = 0f; _jumpRequested = true; } // Crouching input if (inputs.CrouchDown) { _shouldBeCrouching = true; if (!_isCrouching) { _isCrouching = true; Motor.SetCapsuleDimensions(0.5f, 1f, 0.5f); MeshRoot.localScale = new Vector3(1f, 0.5f, 1f); } } else if (inputs.CrouchUp) { _shouldBeCrouching = false; } break; } } }
public void AfterCharacterUpdate(float deltaTime) { switch (CurrentCharacterState) { case CharacterState.Default: // Handle jump-related values { if (Motor.GroundingStatus.FoundAnyGround) { // If we're on a ground surface, reset jumping values CanJump = true; _Animator.SetBool("a_jump", false); _Animator.SetBool("a_landed", true); } else { // Keep track of time since we were last able to jump (for grace period) //_timeSinceLastAbleToJump += deltaTime; CanJump = false; //todo check for falling } } // Handle uncrouching if (_isCrouching && !_shouldBeCrouching) { // Do an overlap test with the character's standing height to see if there are any obstructions Motor.SetCapsuleDimensions(0.5f, 2f, 1f); if (Motor.CharacterOverlap(Motor.TransientPosition, Motor.TransientRotation, _probedColliders, Motor.CollidableLayers, QueryTriggerInteraction.Ignore) > 0) { // If obstructions, just stick to crouching dimensions Motor.SetCapsuleDimensions(0.5f, 1f, 0.5f); } else { // If no obstructions, uncrouch _isCrouching = false; } } break; case CharacterState.Climbing: { switch (_climbingState) { case ClimbingState.Climbing: // Detect getting off ladder during climbing _activeLadder.ClosestPointOnLadderSegment(Motor.TransientPosition, out _onLadderSegmentState); if (Mathf.Abs(_onLadderSegmentState) > 0.05f) { ClimbLadder = false; _climbingState = ClimbingState.DeAnchoring; // If we're higher than the ladder top point if (_onLadderSegmentState > 0) { _ladderTargetPosition = _activeLadder.TopReleasePoint.position; _ladderTargetRotation = _activeLadder.TopReleasePoint.rotation; } // If we're lower than the ladder bottom point else if (_onLadderSegmentState < 0) { _ladderTargetPosition = _activeLadder.BottomReleasePoint.position; _ladderTargetRotation = _activeLadder.BottomReleasePoint.rotation; } } break; case ClimbingState.Anchoring: case ClimbingState.DeAnchoring: // Detect transitioning out from anchoring states if (_anchoringTimer >= AnchoringDuration) { if (_climbingState == ClimbingState.Anchoring) { _climbingState = ClimbingState.Climbing; } else if (_climbingState == ClimbingState.DeAnchoring) { TransitionToState(CharacterState.Default); } } // Keep track of time since we started anchoring _anchoringTimer += deltaTime; break; } break; } } }
public void SetNewPivot(ClimbingState climbingState) { SetPivotCollider(climbingState.PivotCollider, climbingState.PivotPosition, climbingState.PlayerPosition); }