// Update is called once per frame void FixedUpdate() { Vector3 footPos = transform.position + footPositionOffset; if (pathToDestination.Count <= 0 || !DoMovement) { if (DoFriction) { Vector3 frictionVelocity = Vector3.Lerp(Vector3.zero, _rb.velocity, friction); frictionVelocity.y = _rb.velocity.y; _rb.velocity = frictionVelocity; } return; } //Part where we actually move the AI Vector3 moveDir = pathToDestination[0] - footPos; while (moveDir.sqrMagnitude <= popPathPointDistance * popPathPointDistance && DoMovement) { pathToDestination.RemoveAt(0); _remainingGiveUpTime = PathingGiveUpTime; if (pathToDestination.Count <= 0) { if (OnPathComplete != null) { OnPathComplete.Invoke(); } DoMovement = false; } else { moveDir = pathToDestination[0] - footPos; } } moveDir.y = 0.0f; Vector3 newVelocity = _rb.velocity + (moveDir.normalized * acceleration); if (newVelocity.sqrMagnitude >= maxMoveSpeed * maxMoveSpeed) { newVelocity = newVelocity.normalized * maxMoveSpeed; newVelocity.y = _rb.velocity.y; } //_rb.velocity = newVelocity; newVelocity -= _rb.velocity; _rb.AddForce(newVelocity, ForceMode.VelocityChange); if (_remainingGiveUpTime <= 0.0f) { _remainingGiveUpTime = PathingGiveUpTime; pathToDestination.Clear(); DoMovement = false; Debug.Log(name + " says: \"I give up!\""); if (OnGiveUpPathing != null) { OnGiveUpPathing.Invoke(); } } }
private void SetUp(Vector3 start, Vector3 end, OnPathComplete callback) { OnComplete = callback; UpdateStartEnd(start, end); m_SearchIndex = 0; }
public static ABPath Construct(Vector3 start, Vector3 end, OnPathComplete callback = null) { var path = PathPool.GetPath <ABPath>(); path.SetUp(start, end, callback); return(path); }
private void _StartPath(Path path, OnPathComplete callback) { path.OnComplete += callback; m_CurPath = path; m_TmpPathCallback = callback; m_LastPathID = m_CurPath.PathID; _RunModify(m_CurPath); //Todo: Send to NavSystem }
public void StartPath(int startX, int startY, int endX, int endY, OnPathComplete handler) { Log("started path!"); _incompletePaths.Enqueue(new PathRequest() { StartX = startX, StartY = startY, EndX = endX, EndY = endY, Handler = handler }); }
private NavComponent() { m_OnPathComplete = OnPathComplete; m_OnPathPartialComplete = OnPartialPathComplete; }