public virtual void Loop(FP frameTime, IsPosWalkable isWalkable = null, bool bSkipBoids = false) { if (_behaviour.agent == null) { return; } _behaviour.velocity = _behaviour.preVelocity; #if UNITY_EDITOR if (PathFindingManager.DEBUG) { if ((_behaviour as PathFindingAgentBehaviour)._moveStatus != EMoveToSpecStatus.normal) { UnityEngine.Debug.LogError(" moveStatus loop error:" + (_behaviour as PathFindingAgentBehaviour).Id); } } #endif FP fDtSecond = frameTime;// PathFindingManager.instance.DeltaTime * CustomMath.MsToSecond; TSVector newPos = _behaviour.position + _behaviour.velocity * fDtSecond; ENewPosStatus status = isWalkable == null?ENewPosStatus.ok:CheckNewPos(_behaviour.position, ref newPos, isWalkable); if (ENewPosStatus.ok != status) { if (_moveFailedCount < C_maxMoveFailedCount) { _moveFailedCount++; } } if (ENewPosStatus.failed == status) { return; } _behaviour.position = newPos; }
internal ENewPosStatus CheckNewPos(TSVector position, ref TSVector newPos, IsPosWalkable isWalkable) { //TSVector newPos = position + velocity * fDtSecond; ENewPosStatus status = ENewPosStatus.ok; if (PathFindingManager.DEBUG) { #if UNITY_5_5_OR_NEWER && !MULTI_THREAD if (FP.Abs(_behaviour.velocity.x) > _behaviour.maxSpeed * 2 || FP.Abs(_behaviour.velocity.z) > _behaviour.maxSpeed * 2) { UnityEngine.Debug.LogError("velocity error!"); } #endif } if (!isWalkable(newPos)) { TSVector newPosX = newPos; newPosX.x = position.x; TSVector newPosZ = newPos; newPosZ.z = position.z; status = ENewPosStatus.adjust; if (isWalkable(newPosX)) { newPos = newPosX; _behaviour.velocity = CustomMath.Normalize(newPos - _behaviour.position) * _behaviour.preVelocity.magnitude;// _behaviour.maxSpeed; } else if (isWalkable(newPosZ)) { newPos = newPosZ; _behaviour.velocity = CustomMath.Normalize(newPos - _behaviour.position) * _behaviour.preVelocity.magnitude;// * _behaviour.maxSpeed; } else { _behaviour.velocity = TSVector.zero; return(ENewPosStatus.failed); } } return(status); }