UGameplayStatics::BlueprintSuggestProjectileVelocity
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Calculates a launch velocity for a projectile to travel from StartLocation to EndLocation at the given launch speed under gravity. Returns false if no valid solution exists or if the arc is obstructed.
Caveats & Gotchas
- • Two mathematical solutions exist for most arcs (high and low); if neither arc is unobstructed when tracing, the function returns false even if a physical path exists at a different speed.
- • LaunchSpeed must be high enough to physically reach EndLocation given gravity — if too low the function returns false unconditionally regardless of bAcceptClosestOnNoSolutions.
- • The Blueprint-exposed version does not accept a custom CollisionResponseParams; use the native SuggestProjectileVelocity overload with FSuggestProjectileVelocityParameters for finer collision control.
Signature
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, bool bAcceptClosestOnNoSolutions = false); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any UObject within the world to provide world context. | — |
| TossVelocity | FVector& | Output: the calculated launch velocity. | — |
| StartLocation | FVector | Intended launch location of the projectile. | — |
| EndLocation | FVector | Desired landing location. | — |
| LaunchSpeed | float | Desired speed of the projectile at launch. | — |
| OverrideGravityZ | float | Optional gravity override. 0 means use world gravity. | — |
| TraceOption | ESuggestProjVelocityTraceOption::Type | Controls whether to validate a clear path by tracing along the calculated arc. | — |
| CollisionRadius | float | Radius of the projectile (assumed spherical) used when tracing. | — |
| bFavorHighArc | bool | If true and two valid solutions exist, returns the higher arc; otherwise favors the lower arc. | — |
| bDrawDebug | bool | When true, draws a debug arc (red = invalid, green = valid). | — |
| bAcceptClosestOnNoSolutions | bool | If no solution exists, provide a velocity that gets as close as possible to the target. | false |
Return Type
bool Example
Launch a grenade toward a target C++
FVector LaunchVelocity;
bool bSuccess = UGameplayStatics::BlueprintSuggestProjectileVelocity(
this,
LaunchVelocity,
GetActorLocation(),
TargetLocation,
1500.f,
0.f,
ESuggestProjVelocityTraceOption::DoNotTrace,
10.f,
false,
false
);
if (bSuccess)
{
ProjectileComp->Velocity = LaunchVelocity;
} See Also
Version History
Introduced in: 4.6
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?