public bool TryTakeControl(APCharacterController controlled, Collider2D otherCollider) { if (enabled && !m_controlled) { // check grabbing mode if (otherCollider == m_colliderFromTop && m_grabFromTop.m_enabled && m_grabFromTop.m_button.IsSpecified()) { // make sure correct input is pushed while in trigger if (m_grabFromTop.m_button.GetButton()) { // flip player if not facing correctly if (controlled.IsFacingRight() != (m_direction == Direction.Right)) { controlled.GetMotor().Flip(); } StartGrab(controlled, m_grabFromTop.m_anim, m_grabFromTop.m_handle); return(true); } } else if (otherCollider == m_colliderAligned && m_grabInAir.m_enabled) { // make sure we do not grab same edge too quickly while in air if (Time.time - m_releaseTime < controlled.m_edgeGrab.m_minTimeBetweenEdgeGrabs) { return(false); } // check direction if (m_direction == Direction.Right && controlled.IsFacingRight() || m_direction == Direction.Left && !controlled.IsFacingRight()) { StartGrab(controlled, m_grabInAir.m_anim, m_grabInAir.m_handle); return(true); } } } return(false); }
void FixedUpdate() { if (m_controlled) { // always stay on anchor every frame MatchGrabAnchor(); // check if currently exiting if (m_isClimbUpExit) { // wait for end of character animation float fClimbUpExitAnimTime = m_controlled.GetAnim().GetCurrentAnimatorStateInfo(0).normalizedTime; // raise exit power if needed if (m_exitClimbUp.m_maxExitPower > 0f && fClimbUpExitAnimTime >= m_exitClimbUp.m_maxExitPowerAnimTime) { float fClampedInput = GetClampedInput(); m_curExitPower += Time.deltaTime * Time.deltaTime * m_exitClimbUp.m_maxExitPower * fClampedInput; } if (fClimbUpExitAnimTime >= 1f) { // leave control m_isClimbUpExit = false; ReleaseControl(ExitType.ClimbExit); } return; } // do not exit too quickly (wait end of animation in all case) float fAnimTime = m_controlled.GetAnim().GetCurrentAnimatorStateInfo(0).normalizedTime; if ((Time.time - m_grabTime < m_minGrabTime) || fAnimTime < 1f) { return; } // snap to in air handle if grabbing from top and animation is ended (and stop physic animation) /*if (m_bIsGrabbingFromTop && m_controlled.GetAnim().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f) * { * m_bPhysicAnim = false; * m_bIsGrabbingFromTop = false; * m_curGrabHandle = transform.TransformPoint(m_grabInAir.m_handle); * }*/ // check input for leaving this state is pushed or script is disabled float xValue = m_controlled.m_inputs.m_axisX.GetValue(); float yValue = m_controlled.m_inputs.m_axisY.GetValue(); if (!enabled || (m_controlled.IsFacingRight() && xValue < -m_inputExitBack) || (m_controlled.IsFacingRight() && xValue > m_inputExitFront) || (!m_controlled.IsFacingRight() && xValue > m_inputExitBack) || (!m_controlled.IsFacingRight() && xValue < -m_inputExitFront) || (yValue < -m_inputExitDown)) { ReleaseControl(ExitType.Inputs); } // jump exit else if (m_jumpExit && m_controlled.m_jump.m_button.GetButtonDown()) { ReleaseControl(ExitType.Jump); } else { // handle climb up exit if (m_exitClimbUp.m_enabled && m_exitClimbUp.m_button.IsSpecified() && m_exitClimbUp.m_button.GetButton()) { m_isClimbUpExit = true; // launch player physic exit animation InitPhysAnimation(transform.TransformPoint(m_grabInAir.m_handle)); m_controlled.PlayAnim(m_exitClimbUp.m_anim); } } } }