public override void DoAction() { //add 0.1 to y to ignore ground Vector3 spawnPos = new Vector3(blackboard.GetActionDestination().x, blackboard.GetActionDestination().y + 0.1f, blackboard.GetActionDestination().z); //tries left in this frame, before trying again in the next frame. We don't want to block the update-loop for too long. int triesPerFrameLeft = 20; if (maxTriesLeft > 0) { while (triesPerFrameLeft > 0) { float radius = 1.0f; if (Physics.CheckBox(spawnPos, new Vector3(radius, 0, radius))) { ModifySpawnPoint(ref spawnPos, ref triesPerFrameLeft); } else { //check, if the chosen location is marked as blocked if (blackboard.GetBlockedLocations().Count > 0) { bool blocked = Utils.CheckIfBlocked(spawnPos, radius, blackboard.GetBlockedLocations()); if (blocked) { ModifySpawnPoint(ref spawnPos, ref triesPerFrameLeft); continue; } } //reset y before writing to blackboard spawnPos.y = blackboard.GetActionDestination().y; blackboard.SetActionDestination(spawnPos); control.FinishWithSuccess(); return; } } } //After 100 tries this is also a success. We will just work with what we got und let the NavAgent handle the rest. if (maxTriesLeft <= 0) { control.FinishWithSuccess(); } }