【UE4 C++】抛物线路径、发射轨道相关

基于UGameplayStatics

Blueprint_PredictProjectilePath_ByObjectType

  • 根据 Object Type,算出抛物线的点集合和检测结果

    static bool Blueprint_PredictProjectilePath_ByObjectType(
    	const UObject* WorldContextObject,
    	FHitResult& OutHit,
    	TArray<FVector>& OutPathPositions,
    	FVector& OutLastTraceDestination,
    	FVector StartPos,
    	FVector LaunchVelocity,
    	bool bTracePath,
    	float ProjectileRadius,
    	const TArray<TEnumAsByte<EObjectTypeQuery> >& ObjectTypes,
    	bool bTraceComplex,
    	const TArray<AActor*>& ActorsToIgnore,
    	EDrawDebugTrace::Type DrawDebugType,
    	float DrawDebugTime,
    	float SimFrequency = 15.f,
    	float MaxSimTime = 2.f,
    	float OverrideGravityZ = 0
    );
    
  • 代码实现

    FVector BeginLoc = GetActorLocation();
    FVector LaunchVelocity = GetActorForwardVector() * 1000.0f;
    TArray<TEnumAsByte<EObjectTypeQuery> > ObjectTypes;
    ObjectTypes.Add(EObjectTypeQuery::ObjectTypeQuery1);
    TArray<AActor*> IgnoreActors;	
    
    FHitResult HitResult;
    TArray<FVector> OutPatnPositions;
    FVector OutLastTraceDestination;
    
    //开始模拟
    bool bIsHit = UGameplayStatics::Blueprint_PredictProjectilePath_ByObjectType(
    	GetWorld(),
    	HitResult,
    	OutPatnPositions,
    	OutLastTraceDestination,
    	BeginLoc,
    	LaunchVelocity,
    	true,
    	0.0f,
    	ObjectTypes,
    	false,
    	IgnoreActors,
    	EDrawDebugTrace::ForDuration,
    	0.0f
    );
    if (bIsHit)
    {
    	UKismetSystemLibrary::PrintString(GetWorld(), HitResult.GetActor()->GetName());
    }
    

Blueprint_PredictProjectilePath_ByTraceChannel

  • 根据 ChannelChannel,算出抛物线的点集合和检测结果

    static bool Blueprint_PredictProjectilePath_ByTraceChannel(
    	const UObject* WorldContextObject,
    	FHitResult& OutHit,
    	TArray<FVector>& OutPathPositions,
    	FVector& OutLastTraceDestination,
    	FVector StartPos,
    	FVector LaunchVelocity,
    	bool bTracePath,
    	float ProjectileRadius,
    	TEnumAsByte<ECollisionChannel> TraceChannel,
    	bool bTraceComplex,
    	const TArray<AActor*>& ActorsToIgnore,
    	EDrawDebugTrace::Type DrawDebugType,
    	float DrawDebugTime,
    	float SimFrequency = 15.f,
    	float MaxSimTime = 2.f,
    	float OverrideGravityZ = 0
    );
    

PredictProjectilePath

  • 根据预测参数,推算结果

    /**
    	* Predict the arc of a virtual projectile affected by gravity with collision checks along the arc.
    	* Returns true if it hit something.
    	*
    	* @param PredictParams				Input params to the trace (start location, velocity, time to simulate, etc).
    	* @param PredictResult				Output result of the trace (Hit result, array of location/velocity/times for each trace step, etc).
    	* @return							True if hit something along the path (if tracing with collision).
    	*/
    
    static bool PredictProjectilePath(
    	const UObject* WorldContextObject,
    	const FPredictProjectilePathParams& PredictParams,
    	FPredictProjectilePathResult& PredictResult
    );
    

Blueprint_PredictProjectilePath_Advanced

  • 根据预测参数,推算结果

    static bool Blueprint_PredictProjectilePath_Advanced(
    	const UObject* WorldContextObject,
    	const FPredictProjectilePathParams& PredictParams,
    	FPredictProjectilePathResult& PredictResult
    );
    

BlueprintSuggestProjectileVelocity

  • 根据目标点,反算初速度

    static bool BlueprintSuggestProjectileVelocity(
    	const UObject* WorldContextObject,
    	FVector& TossVelocity,
    	FVector StartLocation,
    	FVector EndLocation,
    	float LaunchSpeed,
    	float OverrideGravityZ,
    	ESuggestProjVelocityTraceOption::Type TraceOption,
    	float CollisionRadius,
    	bool bFavorHighArc,
    	bool bDrawDebug
    );
    

SuggestProjectileVelocity_CustomArc

  • 根据目标点,反算初速度

    static bool SuggestProjectileVelocity_CustomArc(
    	const UObject* WorldContextObject,
    	FVector& OutLaunchVelocity,
    	FVector StartPos,
    	FVector EndPos,
    	float OverrideGravityZ = 0,
    	float ArcParam = 0.5f
    );
    

原文链接: https://www.cnblogs.com/shiroe/p/14743685.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    【UE4 C++】抛物线路径、发射轨道相关

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/210361

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 上午12:16
下一篇 2023年2月13日 上午12:16

相关推荐