UGameplayStatics::SuggestProjectileVelocity_MovingTarget
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Calculates a launch velocity to intercept a moving actor in exactly TimeToTarget seconds, assuming the target moves at constant velocity and the projectile is affected only by gravity. Returns false if TargetActor is null.
Caveats & Gotchas
- • The prediction assumes constant target velocity — if the target accelerates, turns, or is physics-driven, the actual hit point diverges from the prediction, especially at longer TimeToTarget values.
- • TimeToTarget is a designer input, not a physically derived value; if the required launch speed to cover the distance in that time is physically unreasonable, the function still returns a velocity — callers must validate speed themselves.
- • Does not perform any collision tracing; the predicted path may pass through static geometry between the launch point and the predicted intercept.
Signature
static ENGINE_API bool SuggestProjectileVelocity_MovingTarget(const UObject* WorldContextObject, FVector& OutLaunchVelocity, FVector ProjectileStartLocation, AActor* TargetActor, FVector TargetLocationOffset = FVector::ZeroVector, double GravityZOverride = 0.f, double TimeToTarget = 1.f, EDrawDebugTrace::Type DrawDebugType = EDrawDebugTrace::Type::None, float DrawDebugTime = 3.f, FLinearColor DrawDebugColor = FLinearColor::Red); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any UObject within the world to provide world context. | — |
| OutLaunchVelocity | FVector& | Output: calculated launch velocity to intercept the target. | — |
| ProjectileStartLocation | FVector | Location the projectile is launched from. | — |
| TargetActor | AActor* | The actor to intercept; its current velocity is used to predict future position. | — |
| TargetLocationOffset | FVector | Offset applied to the predicted target location, e.g. to aim at the actor's chest. | FVector::ZeroVector |
| GravityZOverride | double | Optional override of world gravity Z; 0 uses world gravity. | 0.f |
| TimeToTarget | double | Desired flight time in seconds; clamped to a minimum of 0.1. | 1.f |
| DrawDebugType | EDrawDebugTrace::Type | Debug visualization mode. | EDrawDebugTrace::Type::None |
| DrawDebugTime | float | Duration for debug lines. | 3.f |
| DrawDebugColor | FLinearColor | Color of debug lines. | FLinearColor::Red |
Return Type
bool Example
AI fires leading shot at running player C++
FVector LaunchVelocity;
bool bSuccess = UGameplayStatics::SuggestProjectileVelocity_MovingTarget(
this, LaunchVelocity,
MuzzleLocation,
PlayerActor,
FVector(0, 0, 50.f),
0.f, 0.8f
);
if (bSuccess)
{
FireProjectile(MuzzleLocation, LaunchVelocity);
} See Also
Version History
Introduced in: 5.1
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?