protected virtual void CheckOffMeshLinks() { if (Agent.isOnOffMeshLink && !EnterOFFMESH) //Check if the Agent is on a OFF MESH LINK { EnterOFFMESH = true; //Just to avoid entering here again while we are on a OFF MESH LINK OffMeshLinkData OMLData = Agent.currentOffMeshLinkData; if (OMLData.linkType == OffMeshLinkType.LinkTypeManual) //Means that it has a OffMesh Link component { OffMeshLink CurrentOML = OMLData.offMeshLink; //Check if the OffMeshLink is a Manually placed Link Zone IsOffMeshZone = CurrentOML.GetComponentInParent <Zone>(); //Search if the OFFMESH IS An ACTION ZONE (EXAMPLE CRAWL) if (IsOffMeshZone) //if the OffmeshLink is a zone and is not making an action { IsOffMeshZone.ActivateZone(true); //Activate the Zone return; } var DistanceEnd = (transform.position - CurrentOML.endTransform.position).sqrMagnitude; var DistanceStart = (transform.position - CurrentOML.startTransform.position).sqrMagnitude; //Debug.Log("OMMESH FLY"); if (CurrentOML.CompareTag("Fly")) { var FarTransform = DistanceEnd > DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; //Debug.Log("OMMESH FLY"); FlyOffMesh(FarTransform); } else if (CurrentOML.area == 2) //2 is Off mesh Jump { var NearTransform = DistanceEnd < DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; StartCoroutine(MalbersTools.AlignTransform_Rotation(transform, NearTransform.rotation, 0.15f)); //Aling the Animal to the Link Position animal.State_Activate(StateEnum.Jump); //2 is Jump State //if the OffMesh Link is a Jump type } } else if (OMLData.linkType == OffMeshLinkType.LinkTypeJumpAcross) //Means that it has a OffMesh Link component { animal.State_Activate(StateEnum.Jump); //2 is Jump State } } }
/// <summary> /// Manage all Off Mesh Links /// </summary> protected virtual void CheckOffMeshLinks() { if (Agent.isOnOffMeshLink && !EnterOFFMESH) //Check if the Agent is on a OFF MESH LINK { EnterOFFMESH = true; //Just to avoid entering here again while we are on a OFF MESH LINK OffMeshLinkData OMLData = Agent.currentOffMeshLinkData; if (OMLData.linkType == OffMeshLinkType.LinkTypeManual) //Means that it has a OffMesh Link component { OffMeshLink CurrentOML = OMLData.offMeshLink; //Check if the OffMeshLink is a Manually placed Link ActionZone Is_a_OffMeshZone = CurrentOML.GetComponentInParent <ActionZone>(); //Search if the OFFMESH IS An ACTION ZONE (EXAMPLE CRAWL) if (Is_a_OffMeshZone && !DoingAnAction) //if the OffmeshLink is a zone and is not making an action { animal.Action = DoingAnAction = true; //Activate the Action on the Animal return; } var DistanceEnd = (transform.position - CurrentOML.endTransform.position).sqrMagnitude; var DistanceStart = (transform.position - CurrentOML.startTransform.position).sqrMagnitude; var NearTransform = DistanceEnd < DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; var FarTransform = DistanceEnd > DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; StartCoroutine(MalbersTools.AlignTransform_Rotation(transform, NearTransform.rotation, 0.15f)); //Aling the Animal to the Link Position if (animal.canFly && CurrentOML.CompareTag("Fly")) { Debuging(name + ": Fly OffMesh"); StartCoroutine(CFlyOffMesh(FarTransform)); } else if (CurrentOML.area == 2) { animal.SetJump(); //if the OffMesh Link is a Jump type } } else if (OMLData.linkType == OffMeshLinkType.LinkTypeJumpAcross) //Means that it has a OffMesh Link component { animal.SetJump(); } } }
/// <summary> /// Used for checking if the animal enables the action /// </summary> private void OnActionListener() { if (!oldAnimal) { return; //Skip if there's no animal } StartCoroutine(OnActionDelay(ActionDelay, oldAnimal)); //Invoke the Event OnAction if (Align && AlingPoint) { IEnumerator ICo = null; Vector3 AlingPosition = AlingPoint.position; if (AlingPoint2) //In case there's { AlingPosition = MalbersTools.ClosestPointOnLine(AlingPoint.position, AlingPoint2.position, oldAnimal.transform.position); } if (AlignLookAt) { ICo = MalbersTools.AlignLookAtTransform(oldAnimal.transform, AlingPoint, AlignTime, AlignCurve); //Align Look At the Zone StartCoroutine(ICo); } else { if (AlignPos) { StartCoroutine(MalbersTools.AlignTransform_Position(oldAnimal.transform, AlingPosition, AlignTime, AlignCurve)); } if (AlignRot) { StartCoroutine(MalbersTools.AlignTransform_Rotation(oldAnimal.transform, AlingPoint.rotation, AlignTime, AlignCurve)); } } } StartCoroutine(CheckForCollidersOff()); }
/// <summary>Aligns the Animal to the Align points of the Zone</summary> public virtual void AlignAnimal() { if (Align && AlingPoint && CurrentAnimal != null) { IEnumerator ICo = null; if (AlignLookAt) { ICo = MalbersTools.AlignLookAtTransform(CurrentAnimal.transform, AlingPoint, AlignTime, AlignCurve); //Align Look At the Zone StartCoroutine(ICo); } else { if (AlignPos) { Vector3 AlingPosition = AlingPoint.position; if (AlingPoint2) //In case there's a line ... move to the closest point between the two transforms { AlingPosition = MalbersTools.ClosestPointOnLine(AlingPoint.position, AlingPoint2.position, CurrentAnimal.transform.position); } if (DoubleSided) { Vector3 AlingPosOpposite = transform.InverseTransformPoint(AlingPosition); AlingPosOpposite.z *= -1; AlingPosOpposite = transform.TransformPoint(AlingPosOpposite); var Distance1 = Vector3.Distance(CurrentAnimal.transform.position, AlingPosition); var Distance2 = Vector3.Distance(CurrentAnimal.transform.position, AlingPosOpposite); if (Distance2 < Distance1) { StartCoroutine(MalbersTools.AlignTransform_Position(CurrentAnimal.transform, AlingPosOpposite, AlignTime, AlignCurve)); } else { StartCoroutine(MalbersTools.AlignTransform_Position(CurrentAnimal.transform, AlingPosition, AlignTime, AlignCurve)); } } else { StartCoroutine(MalbersTools.AlignTransform_Position(CurrentAnimal.transform, AlingPosition, AlignTime, AlignCurve)); } } if (AlignRot) { Quaternion Side1 = AlingPoint.rotation; Quaternion AnimalRot = CurrentAnimal.transform.rotation; if (DoubleSided) { Quaternion Side2 = AlingPoint.rotation * Quaternion.Euler(0, 180, 0); var Side1Angle = Quaternion.Angle(AnimalRot, Side1); var Side2Angle = Quaternion.Angle(AnimalRot, Side2); StartCoroutine(MalbersTools.AlignTransform_Rotation(CurrentAnimal.transform, Side1Angle < Side2Angle ? Side1 : Side2, AlignTime, AlignCurve)); } else { StartCoroutine(MalbersTools.AlignTransform_Rotation(CurrentAnimal.transform, Side1, AlignTime, AlignCurve)); } } } } }