当前位置: 首页>>代码示例>>C++>>正文


C++ UNavigationSystem::GetRandomReachablePointInRadius方法代码示例

本文整理汇总了C++中UNavigationSystem::GetRandomReachablePointInRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ UNavigationSystem::GetRandomReachablePointInRadius方法的具体用法?C++ UNavigationSystem::GetRandomReachablePointInRadius怎么用?C++ UNavigationSystem::GetRandomReachablePointInRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UNavigationSystem的用法示例。


在下文中一共展示了UNavigationSystem::GetRandomReachablePointInRadius方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ExecuteTask

// execution
EBTNodeResult::Type UAIE_GoToRandom_BTTaskNode::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) {
	/*	call super 
	 *	should aquire refrences for our BehaviorTreeComp, BlackboardComp, AIController, and BotCharacter
	 *	will return EBTNodeResult::Succeeded if we have all of them
	 *	will return EBTNodeResult::Failed if it failed to grab any of them
	*/
	EBTNodeResult::Type resultFromSuperExecution = Super::ExecuteTask(OwnerComp, NodeMemory);
	// check that we successfully grabbed the BehaviorTreeComp, BlackboardComp, AIController, and BotCharacter
	if (resultFromSuperExecution == EBTNodeResult::Succeeded) {
		// check that we can get the World
		if (GetWorld()) {
			// get the current nav system from the world
			UNavigationSystem* navSystem = UNavigationSystem::GetCurrent(GetWorld());
			// check that we have a nav system
			if (navSystem) {
				// get our actors current location to pe used as our start position
				FVector startPosi = BotCharacter->GetActorLocation();
				// create a nav location to be used as our end position 
				// default will be set to our current position in case of failure to find a suitable end position
				FNavLocation endPosi = FNavLocation(startPosi);
				// attempt to get a random new position
				if (navSystem->GetRandomReachablePointInRadius(startPosi, searchRadius, endPosi)) {
					// if we were successfull in finding a new location get the MoveToLocation BlackboardKeyID
					FBlackboard::FKey BlackboardKey_MoveToLocation = Blackboard->GetKeyID("MoveToLocation");
					// check that we got the key
					if ( Blackboard->IsValidKey( BlackboardKey_MoveToLocation)) {
						// set the MoveToLocation BlackboardKeyID to our new location
						Blackboard->SetValue<UBlackboardKeyType_Vector>(BlackboardKey_MoveToLocation, endPosi.Location);
						// return succeeded now that we have set up our new loacation
						return EBTNodeResult::Succeeded;
					}
					else {
						// return Aborted if we can't find the Key as it will never succeed without a proper Key
						if (bForceSuccess) {
							return EBTNodeResult::Succeeded;
						}
						return EBTNodeResult::Aborted;
					}
				}
				// return in progress if their are currently no valid locations
				if (bForceSuccess) {
					return EBTNodeResult::Succeeded;
				}
				return EBTNodeResult::InProgress;
			}
		}
		 
		
	}
	// we will only get here if execution fails so we will check if force success is on
	if (bForceSuccess) {
		// if force success is on we will return Succeeded anyway
		return EBTNodeResult::Succeeded;
	}
	// we want to return Failed after the force success check
	return EBTNodeResult::Failed;
}
开发者ID:JDonDuncan,项目名称:AI_Example,代码行数:58,代码来源:AIE_GoToRandom_BTTaskNode.cpp


注:本文中的UNavigationSystem::GetRandomReachablePointInRadius方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。