`
aigo
  • 浏览: 2542429 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌
社区版块
存档分类
最新评论

[UE4]引擎自带的自动寻路组件:NavMeshBoundsVolume

UE4 
阅读更多

如果要使用 UE4自带的自动寻路功能,除了需要调用寻路相关的API以外,还要设置寻路组件:NavMeshBoundsVolume,否则调用寻路API时无效。

更详细的说明见官方文档:https://docs.unrealengine.com/latest/INT/Resources/ContentExamples/NavMesh/index.html

 

1,首先向场景中拖入NavMeshBoundsVolume组件:


 
 

2,然后点击build,build成功以后,按键盘P键,可以看到build后的有效寻路区域,绿色标识


 
 

3,这个时候就可以使用相关的寻路API了。下面是官方TopDown模版中使用的自动寻路代码:

UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();

void AMyPlayerController::SetNewMoveDestination(const FVector DestLocation)
{
	APawn* const Pawn = GetPawn();
	if (Pawn)
	{
		UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
		float const Distance = FVector::Dist(DestLocation, Pawn->GetActorLocation());

		// We need to issue move command only if far enough in order for walk animation to play correctly
		if (NavSys && (Distance > 120.0f))
		{
			NavSys->SimpleMoveToLocation(this, DestLocation);
		}
	}
}

 
 

  • 大小: 70 KB
  • 大小: 135.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics