// Update is called once per frame void Update() { if (wandering == true) { // update timer timer += Time.deltaTime; // X: Adjust the speed if we're on a navmesh. Unity is weird sometimes... if (agent.isOnOffMeshLink) { UnityEngine.AI.OffMeshLinkData link = agent.currentOffMeshLinkData; float dist = Vector3.Distance(link.startPos, link.endPos); agent.speed = navSpeed * dist; } else { agent.speed = realSpeed; } // check if the object needs a path and provide it with one if need be. if (!agent.hasPath && !agent.isOnOffMeshLink) { Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1); agent.SetDestination(newPos); timer = 0; } if (timer >= wanderTimer && !agent.isOnOffMeshLink) { Vector3 newPos = RandomNavSphere(transform.position, wanderRadius, -1); agent.SetDestination(newPos); timer = 0; } } }
int getOffMeshLinkAction(Unit unit) { if (!mAgent.isOnOffMeshLink) { return(0); } UnityEngine.AI.OffMeshLinkData lk = mAgent.currentOffMeshLinkData; mAgent.autoTraverseOffMeshLink = false; Vector3 b = lk.startPos; Vector3 e = lk.endPos; if (Vector3.Distance(unit.pos, b) > Vector3.Distance(unit.pos, e)) { b = lk.endPos; e = lk.startPos; } int lnkType = lk.offMeshLink.area; switch (lnkType) { case 2: //mUnit.StartCoroutine (jump (b,e)); return(1); case 3: //mUnit.StartCoroutine (climb (b,e)); return(1); } return(0); }
static public int constructor(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.AI.OffMeshLinkData o; o = new UnityEngine.AI.OffMeshLinkData(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
IEnumerator NormalSpeed(UnityEngine.AI.NavMeshAgent agent) { UnityEngine.AI.OffMeshLinkData data = agent.currentOffMeshLinkData; Vector3 endPos = data.endPos + Vector3.up * agent.baseOffset; while (agent.transform.position != endPos) { agent.transform.position = Vector3.MoveTowards(agent.transform.position, endPos, agent.speed * Time.deltaTime); yield return(null); } }
static public int constructor(IntPtr l) { try { UnityEngine.AI.OffMeshLinkData o; o = new UnityEngine.AI.OffMeshLinkData(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
IEnumerator Curve(UnityEngine.AI.NavMeshAgent agent, float duration) { UnityEngine.AI.OffMeshLinkData data = agent.currentOffMeshLinkData; Vector3 startPos = agent.transform.position; Vector3 endPos = data.endPos + Vector3.up * agent.baseOffset; float normalizedTime = 0.0f; while (normalizedTime < 1.0f) { float yOffset = curve.Evaluate(normalizedTime); agent.transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up; normalizedTime += Time.deltaTime / duration; yield return(null); } }
static int get_nextOffMeshLinkData(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UnityEngine.AI.NavMeshAgent obj = (UnityEngine.AI.NavMeshAgent)o; UnityEngine.AI.OffMeshLinkData ret = obj.nextOffMeshLinkData; ToLua.PushValue(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index nextOffMeshLinkData on a nil value")); } }
// --------------------------------------------------------- // 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(); }
private extern void GetNextOffMeshLinkDataInternal_Injected(out OffMeshLinkData ret);