/// <summary> /// start trigger interaction /// </summary> /// <param name="character">character interacting with trigger</param> /// <param name="limbsIK">ik helper</param> /// <param name="use">use flag</param> /// <param name="jump">jump flag</param> /// <param name="v">vertical value</param> /// <param name="h">horizontal value</param> /// <returns>all succeded</returns> public override bool start(TPCharacter character, IKHelper limbsIK, bool use, bool secondaryUse, bool jump, float v, float h) { if (!character) { #if DEBUG_INFO Debug.LogError("object cannot be null!" + " < " + this.ToString() + ">"); #endif return(false); } if (!Target) { #if DEBUG_INFO Debug.LogWarning("trigger target not assigned!" + " < " + this.ToString() + ">"); #endif return(false); } if (!use) { return(false); } //if (!m_TriggerInfo) m_TriggerInfo = new TriggerInfo(); m_TriggerInfo.doMatchTarget = false; m_TriggerInfo.doRotationToTarget = false; Vector3 direction = GoingUp ? Target.forward : -Target.forward; float distanceFromTarget = (character.transform.position - Target.position).magnitude; float angle = Vector3.Angle(character.transform.forward, direction) * 0.002f; float pos_rot_time = distanceFromTarget + angle; if (pos_rot_time < 0.1f) { if (limbsIK) { limbsIK.handIKMode = IKMode.ToLine; limbsIK.setIKDirection(true); if (LeftHandHold) { limbsIK.LeftHandPtA = LeftHandHold.position - LeftHandHold.up * 100.0f; limbsIK.LeftHandPtB = LeftHandHold.position + LeftHandHold.up * 100.0f; limbsIK.LHandIKEnabled = true; limbsIK.LHWeightTime = 0.0f; } else { limbsIK.LHandIKEnabled = false; } if (RightHandHold) { limbsIK.RightHandPtA = RightHandHold.position - RightHandHold.up * 100.0f; limbsIK.RightHandPtB = RightHandHold.position + RightHandHold.up * 100.0f; limbsIK.RHandIKEnabled = true; limbsIK.RHWeightTime = 0.0f; } else { limbsIK.RHandIKEnabled = false; } limbsIK.feetIKMode = IKMode.ToPlane; if (LeftFootHold) { Vector3 lpt1 = LeftFootHold.position; Vector3 lpt2 = lpt1 + LeftFootHold.up; Vector3 lpt3 = lpt1 + LeftFootHold.forward; limbsIK.LeftFootPlane.Set3Points(lpt1, lpt2, lpt3); limbsIK.LFootIKEnabled = true; } else { limbsIK.LFootIKEnabled = false; } if (RightFootHold) { Vector3 rpt1 = RightFootHold.position; Vector3 rpt2 = rpt1 + RightFootHold.up; Vector3 rpt3 = rpt1 + RightFootHold.forward; limbsIK.RightFootPlane.Set3Points(rpt1, rpt2, rpt3); limbsIK.RFootIKEnabled = true; } else { limbsIK.RFootIKEnabled = false; } } character.disablePhysics(false, true); character.OnSetTransform = () => { //set steps audio clips to character character.audioManager.ladderClips = ladderSounds; character.disablePhysics(false, true); if (GoingUp) { character.animator.SetBool(/*"pLadderUp"*/ HashIDs.LadderUpBool, true); } else { character.animator.SetBool(/*"pLadderDown"*/ HashIDs.LadderDownBool, true); } character.animator.SetInteger(/*"pLadderSize"*/ HashIDs.LadderSizeInt, (int)LadderSize); character.OnSetTransform = null; }; Quaternion targetRot = Target.rotation; if (switchTargetDirection) { targetRot *= Quaternion.AngleAxis(180, character.transform.up); } if (!GoingUp) { targetRot *= Quaternion.AngleAxis(180, character.transform.up); } character.setTransform(Target.position, targetRot, true); character.triggerRootMotion = true; } else { float forw = 0.5f; bool crouch = false; character.OnLerpEnd = () => { if (limbsIK) { limbsIK.handIKMode = IKMode.ToLine; limbsIK.setIKDirection(true); if (LeftHandHold) { limbsIK.LeftHandPtA = LeftHandHold.position - LeftHandHold.up * 100.0f; limbsIK.LeftHandPtB = LeftHandHold.position + LeftHandHold.up * 100.0f; limbsIK.LHandIKEnabled = true; limbsIK.LHWeightTime = 0.0f; } else { limbsIK.LHandIKEnabled = false; } if (RightHandHold) { limbsIK.RightHandPtA = RightHandHold.position - RightHandHold.up * 100.0f; limbsIK.RightHandPtB = RightHandHold.position + RightHandHold.up * 100.0f; limbsIK.RHandIKEnabled = true; limbsIK.RHWeightTime = 0.0f; } else { limbsIK.RHandIKEnabled = false; } limbsIK.feetIKMode = IKMode.ToPlane; if (LeftFootHold) { Vector3 lpt1 = LeftFootHold.position; Vector3 lpt2 = lpt1 + LeftFootHold.up; Vector3 lpt3 = lpt1 + LeftFootHold.forward; limbsIK.LeftFootPlane.Set3Points(lpt1, lpt2, lpt3); limbsIK.LFootIKEnabled = true; } else { limbsIK.LFootIKEnabled = false; } if (RightFootHold) { Vector3 rpt1 = RightFootHold.position; Vector3 rpt2 = rpt1 + RightFootHold.up; Vector3 rpt3 = rpt1 + RightFootHold.forward; limbsIK.RightFootPlane.Set3Points(rpt1, rpt2, rpt3); limbsIK.RFootIKEnabled = true; } else { limbsIK.RFootIKEnabled = false; } } //set steps audio clips to character character.audioManager.ladderClips = ladderSounds; character.disablePhysics(false, true); if (GoingUp) { character.animator.SetBool(/*"pLadderUp"*/ HashIDs.LadderUpBool, true); } else { character.animator.SetBool(/*"pLadderDown"*/ HashIDs.LadderDownBool, true); } character.animator.SetInteger(/*"pLadderSize"*/ HashIDs.LadderSizeInt, (int)LadderSize); character.transform.position = Target.position; character.triggerRootMotion = true; character.OnLerpEnd = null; }; character.disableMove = true; Quaternion targetRot = Target.rotation; if (switchTargetDirection) { targetRot *= Quaternion.AngleAxis(180, character.transform.up); } if (!GoingUp) { targetRot *= Quaternion.AngleAxis(180, character.transform.up); } character.lerpToTransform( Target.position, targetRot, pos_rot_time, pos_rot_time, forw, crouch ); } return(true); }