/// <summary> /// end trigger animations /// </summary> /// <param name="character">character interacting with trigger</param> /// <param name="limbsIK">ik helper</param> public override void end(TPCharacter character, IKHelper limbsIK) { if (!character) { #if DEBUG_INFO Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">"); #endif return; } if (!Target) { #if DEBUG_INFO Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">"); #endif return; } character.triggerRootMotion = false; character.disableMove = false; character.setMoveMode(TPCharacter.MovingMode.Ledge); OrbitCameraController oc = character.GetComponentInChildren <OrbitCameraController>(); if (oc) { oc.additiveRotation = true; } character.disableCapsuleScale = true; character.animator.SetBool(/*"pGrabLedgeUp"*/ HashIDs.GrabLedgeUpBool, false); character.animator.SetBool(/*"pOnLedge"*/ HashIDs.OnLedgeBool, true); character.animatorDampTime = 0.0f; character.ledgeMove = true; character.disableLedgeConstraint = false; character.fullStop(); character.jumpAllowed = true; if (limbsIK) { limbsIK.RHandIKEnabled = true; limbsIK.LFootIKEnabled = true; limbsIK.RFootIKEnabled = true; limbsIK.LHandIKEnabled = true; limbsIK.LFWeightTime = 0.0f; limbsIK.RFWeightTime = 0.0f; limbsIK.startLedgeAdjust(m_TriggerInfo.targetRotation); limbsIK.checkHang = true; } if (character.animator.GetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool)) { character.restoreCapsuleSize(); } else { character.scaleCapsuleToHalf(); } }
/// <summary> /// method for checking does player is facing wall when on ledge /// </summary> private void _checkHangFunc() { if (!m_Character.ledgeMove) { return; } if (!m_CheckHang) { return; } bool hang = true; bool hanging = m_Character.animator.GetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool); float radius = m_Character.capsule.radius * 0.38f; RaycastHit hit; int mask = m_Character.layers; Vector3 checkStart = transform.position; Vector3 closest = MathUtils.GetClosestPoint2Line(m_Character.ledge.leftPoint, m_Character.ledge.rightPoint, ref checkStart); Ray ray = new Ray(checkStart, Vector3.up); float rayDist = 0.0f; if (m_Character.ledge.plane.Raycast(ray, out rayDist)) { closest = checkStart + Vector3.up * rayDist; closest = MathUtils.GetClosestPoint2Line(m_Character.ledge.leftPoint, m_Character.ledge.rightPoint, ref closest); } Vector3 offset = new Vector3(0.0f, 1.0f, 0.25f); offset = transform.rotation * offset; Vector3 pos = closest - offset; float dist = hangCheckDistance + 0.25f; ray = new Ray(pos, transform.forward); #if DEBUG_INFO HANGCHECKCOL = Color.white; HANGCHECKDIST = dist; HANGCHECKPOS = ray.origin; #endif float MAX_DIST_NOMOVE = 0.32f; m_LedgeAdjustion = Vector3.zero; if (Physics.SphereCast(ray, radius, out hit, dist, mask)) { #if DEBUG_INFO HANGCHECKCOL = Color.red; #endif if (hit.distance > MAX_DIST_NOMOVE) { float addedDist = MAX_DIST_NOMOVE - hit.distance; m_LedgeAdjustion = -transform.forward * addedDist; } hang = false; } if (hang) { if (!hanging) { m_Character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, true); currentRelLedgePosition = ledgeRelativePositionHang; startLedgeAdjust(transform.rotation); m_Character.restoreCapsuleSize(); } } else { if (hanging) { m_Character.animator.SetBool(/*"pLedgeHang"*/ HashIDs.LedgeHangBool, false); currentRelLedgePosition = ledgeRelativePosition; startLedgeAdjust(transform.rotation); m_Character.scaleCapsuleToHalf(); } } }