BlueprintSuggestProjectileVelocity是基于SuggestProjectileVelocity实现的,因此看后者实现即可。
bool UGameplayStatics::BlueprintSuggestProjectileVelocity(const UObject* WorldContextObject, FVector& OutTossVelocity, FVector StartLocation, FVector EndLocation, float LaunchSpeed, float OverrideGravityZ, ESuggestProjVelocityTraceOption::Type TraceOption, float CollisionRadius, bool bFavorHighArc, bool bDrawDebug)
{
// simple pass-through to the C++ interface
return UGameplayStatics::SuggestProjectileVelocity(WorldContextObject, OutTossVelocity, StartLocation, EndLocation, LaunchSpeed, bFavorHighArc, CollisionRadius, OverrideGravityZ, TraceOption, FCollisionResponseParams::DefaultResponseParam, TArray<AActor*>(), bDrawDebug);
}
声明
//GameplayStatics.h
/**
* Calculates an launch velocity for a projectile to hit a specified point.
* @param TossVelocity (output) Result launch velocity.
* @param StartLocation Intended launch location
* @param EndLocation Desired landing location
* @param LaunchSpeed Desired launch speed
* @param OverrideGravityZ Optional gravity override. 0 means "do not override".
* @param TraceOption Controls whether or not to validate a clear path by tracing along the calculated arc
* @param CollisionRadius Radius of the projectile (assumed spherical), used when tracing
* @param bFavorHighArc If true and there are 2 valid solutions, will return the higher arc. If false, will favor the lower arc.
* @param bDrawDebug When true, a debug arc is drawn (red for an invalid arc, green for a valid arc)
* @return Returns false if there is no valid solution or the valid solutions are blocked. Returns true otherwise.
*/
UFUNCTION(BlueprintCallable, Category="Game|Components|ProjectileMovement", DisplayName="SuggestProjectileVelocity", meta=(WorldContext="WorldContextObject"))
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);
/** Native version, has more options than the Blueprint version. */
static bool SuggestProjectileVelocity(const UObject* WorldContextObject, FVector& TossVelocity, FVector StartLocation, FVector EndLocation, float TossSpeed, bool bHighArc = false, float CollisionRadius = 0.f, float OverrideGravityZ = 0, ESuggestProjVelocityTraceOption::Type TraceOption = ESuggestProjVelocityTraceOption::TraceFullPath, const FCollisionResponseParams& ResponseParam = FCollisionResponseParams::DefaultResponseParam, const TArray<AActor*>& ActorsToIgnore = TArray<AActor*>(), bool bDrawDebug = false);
BlueprintSuggestProjectileVelocity
/** * 计算弹丸击中指定点的发射速度。 * @param TossVelocity(输出)结果发射速度。 * @param StartLocation 预期启动位置 * @param EndLocation 期望的着陆位置 * @param LaunchSpeed 所需的启动速度 * @param OverrideGravityZ 可选的重力覆盖。 0 表示“不覆盖”。 * @param TraceOption 控制是否通过沿计算的弧线追踪来验证畅通路径 * @param CollisionRadius 弹丸的半径(假定为球形),在追踪时使用 * @param bFavorHighArc 如果为真并且有 2 个有效的解决方案,将返回更高的弧。 如果为假,将有利于较低的弧度。 * @param bDrawDebug 当为真时,绘制一个调试弧(红色为无效弧,绿色为有效弧) * @return 如果没有有效的解决方案或有效的解决方案被阻止,则返回 false。 否则返回真。 */
SuggestProjectileVelocity
/** 原生版本,比蓝图版本有更多的选项。 */
实现
理论参考
https://en.wikipedia.org/wiki/Projectile_motion#Angle_required_to_hit_coordinate_.28x.2Cy.29
|