public override void ProcessStep() { _childData = navHandleData.GetChildNavData(); if (_childData != null) { NavGroup group = (NavGroup)navHandleData.entity; for (int i = 0; i < _childData.Count; i++) { _slotInfo = group.GetSlotInfoByEntityID(_childData[i].entityID); if (_slotInfo == null) { continue; } float speed = _childData[i].entity.maxSpeed; float distance = Vector3.Distance(NavEntity.GetCurrentPosition(_childData[i].entityID), _slotInfo.slotWorldPosition) * (1f / NavHandleData.NAV_TICK_TIME); // 例如 一秒内距离小于3 速度为3 则速度为初始最大不变 // 若距离大于3 例如6 则为两倍速 if (distance > speed) { speed = (distance / speed) * speed; } _childData[i].realVelocity = (_slotInfo.slotWorldPosition - NavEntity.GetCurrentPosition(_childData[i].entityID)).normalized * speed; Simulator.Instance.setAgentPrefVelocity(i, _childData[i].realVelocity.ToRVOVec2()); //var dir = navHandleData.destination.XZ() - NavEntity.GetCurrentPosition(_childData[i].entityID).XZ(); //Simulator.Instance.setAgentPrefVelocity(i, RVOMath.normalize(dir.ToRVOVec2())); } } }
public Vector3 GetPathfindingVelocity() { if (wayPointList != null && nextWaypointIndex < wayPointList.Count) { return((wayPointList[nextWaypointIndex].XZ() - NavEntity.GetCurrentPosition(entityID).XZ()).normalized //* NavEntity.GetMaxSpeed(entityID); * GetChildMinSpeed()); } return(Vector3.zero); }
public void UpdateWayPointIndex() { if (wayPointList != null) { if (nextWaypointIndex < wayPointList.Count) { if (Vector3.Distance( NavEntity.GetCurrentPosition(entityID).XZ(), wayPointList[nextWaypointIndex].XZ() ) < CHECKED_DISTANCE) { nextWaypointIndex++; if (nextWaypointIndex == wayPointList.Count) { Debug.Log("寻路路径已经走完"); } } } } }
public override void ProcessStep() { if (navHandleData.isGroup) { _cachedGroup = (navHandleData.entity as NavGroup); if (_cachedGroup == null) { Debug.LogError("组对象为空!"); return; } Vector3 currentPosition = NavEntity.GetCurrentPosition(navHandleData.entityID); Vector3 nextPosition = currentPosition + navHandleData.realVelocity * NavHandleData.NAV_TICK_TIME; _cachedGroup.AssignSlots(nextPosition, navHandleData.realVelocity.normalized); _childData = navHandleData.GetChildNavData(); for (int i = 0; i < _childData.Count; i++) { _childData[i].slotPositionWhenAsChild = _cachedGroup.GetSlotInfoByEntityID(_childData[i].entityID).slotWorldPosition; } Debug.DrawLine(currentPosition, nextPosition, Color.magenta, NavHandleData.NAV_TICK_TIME); } }
private bool CheckChildrenReached() { if (isGroup == false || _childEntityDataList.Count == 0) { return(true); } else { bool allReached = true; for (int i = 0; i < _childEntityDataList.Count; i++) { if (Vector3.Distance(NavEntity.GetCurrentPosition(_childEntityDataList[i].entityID).XZ(), _childEntityDataList[i].slotPositionWhenAsChild.XZ()) > CHECKED_DISTANCE) { allReached = false; break; } } return(allReached); } }
public bool HasReachedTarget() { return(Vector3.Distance(NavEntity.GetCurrentPosition(entityID).XZ(), destination.XZ()) < CHECKED_DISTANCE && CheckChildrenReached()); }