IEnumerator Start() { UnityEngine.AI.NavMeshAgent agent = GetComponent <UnityEngine.AI.NavMeshAgent> (); agent.autoTraverseOffMeshLink = false; while (true) { if (agent.isOnOffMeshLink) { if (method == OffMeshLinkMoveMethod.NormalSpeed) { yield return(StartCoroutine(NormalSpeed(agent))); } else if (method == OffMeshLinkMoveMethod.Parabola) { yield return(StartCoroutine(Parabola(agent, 2.0f, 0.5f))); } else if (method == OffMeshLinkMoveMethod.Curve) { yield return(StartCoroutine(Curve(agent, 0.5f))); } agent.CompleteOffMeshLink(); } yield return(null); } }
static public int CompleteOffMeshLink(IntPtr l) { try { UnityEngine.AI.NavMeshAgent self = (UnityEngine.AI.NavMeshAgent)checkSelf(l); self.CompleteOffMeshLink(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static int CompleteOffMeshLink(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.AI.NavMeshAgent obj = (UnityEngine.AI.NavMeshAgent)ToLua.CheckObject(L, 1, typeof(UnityEngine.AI.NavMeshAgent)); obj.CompleteOffMeshLink(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
// Update is called once per frame void FixedUpdate() { agent.destination = goal.transform.position; Vector3 worldDeltaPosition = agent.nextPosition - transform.position; float turnSpeed = Vector3.Dot(Vector3.up, Vector3.Cross(transform.forward, worldDeltaPosition)); character.SetTurnSpeed(turnSpeed); float forwardSpeed = Vector3.Dot(transform.forward, worldDeltaPosition); character.SetForwardSpeed(forwardSpeed); if (agent.isOnOffMeshLink) { character.Jump(); agent.CompleteOffMeshLink(); } }
void Update() { switch (state) { case AnimState.RUN: if (agent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathComplete && agent.remainingDistance <= 0 && !agent.pathPending) { state = AnimState.IDLE; anim.SetInteger("state", AnimState.IDLE); } else { if (agent.isOnOffMeshLink) { agent.CompleteOffMeshLink(); } } break; } }
private IEnumerator CheckOffMeshLinkMove() { if (agent.isOnOffMeshLink) { if (Method == OffMeshLinkMoveMethod.NormalSpeed) { yield return(StartCoroutine(NormalSpeed(agent))); } else if (Method == OffMeshLinkMoveMethod.Parabola) { yield return(StartCoroutine(Parabola(agent, 2.0f, 0.5f))); } else if (Method == OffMeshLinkMoveMethod.Curve) { yield return(StartCoroutine(Curve(agent, 0.5f))); } agent.CompleteOffMeshLink(); } yield return(null); }
// --------------------------------------------------------- // Name : Jump // Desc : Manual OffMeshLInk traversal using an Animation // Curve to control agent height. // --------------------------------------------------------- IEnumerator Jump(float duration) { // Get the current OffMeshLink data UnityEngine.AI.OffMeshLinkData data = _navAgent.currentOffMeshLinkData; // Start Position is agent current position Vector3 startPos = _navAgent.transform.position; // End position is fetched from OffMeshLink data and adjusted for baseoffset of agent Vector3 endPos = data.endPos + (_navAgent.baseOffset * Vector3.up); // Used to keep track of time float time = 0.0f; // Keeo iterating for the passed duration while (time <= duration) { // Calculate normalized time float t = time / duration; // Lerp between start position and end position and adjust height based on evaluation of t on Jump Curve _navAgent.transform.position = Vector3.Lerp(startPos, endPos, t) + (JumpCurve.Evaluate(t) * Vector3.up); // Accumulate time and yield each frame time += Time.deltaTime; yield return(null); } // NOTE : Added this for a bit of stability to make sure the // Agent is EXACTLY on the end position of the off mesh // link before completeing the link. _navAgent.transform.position = endPos; // All done so inform the agent it can resume control _navAgent.CompleteOffMeshLink(); }