AAIController::SuggestTossVelocity
#include "AIController.h"
Access: public
Description
Computes a launch velocity that will arc a projectile from Start to End under gravity at the given speed. Returns false if no valid trajectory exists (target out of range or obstructed).
Caveats & Gotchas
- • Potentially expensive — it runs physics traces along the arc. CollisionRadius > 0 combined with bOnlyTraceUp = false is the worst-case path; throttle call frequency or cache results for high-frequency AI shooters.
- • Assumes the projectile is affected only by gravity after launch — no drag, no homing, no custom forces. If your projectile uses a custom movement component, the computed velocity will be wrong.
- • Returns false when the horizontal distance exceeds what TossSpeed can reach under the current world gravity. OutTossVelocity is left unchanged on failure; the caller must check the return value before applying the velocity.
Signature
bool SuggestTossVelocity(FVector& OutTossVelocity, FVector Start, FVector End, float TossSpeed, bool bPreferHighArc, float CollisionRadius = 0, bool bOnlyTraceUp = false) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| OutTossVelocity | FVector& | Output: the computed initial velocity to apply to the projectile. | — |
| Start | FVector | World-space launch origin of the arc. | — |
| End | FVector | World-space target point of the arc. | — |
| TossSpeed | float | Initial launch speed of the projectile in cm/s. | — |
| bPreferHighArc | bool | When two solutions exist, prefer the higher arc trajectory. | — |
| CollisionRadius | float | Bounding radius of the projectile for clearance checks; 0 for point traces. | 0 |
| bOnlyTraceUp | bool | When true, collision checks are only performed on the ascending portion of the arc. | false |
Return Type
bool Example
Compute and apply a grenade toss velocity C++
FVector LaunchVelocity;
APawn* MyPawn = GetPawn();
if (!MyPawn) return;
FVector MuzzleLocation = MyPawn->GetActorLocation() + FVector(0, 0, 50.f);
if (SuggestTossVelocity(LaunchVelocity, MuzzleLocation, TargetLocation, 1200.f, /*bPreferHighArc=*/false))
{
AGrenade* Grenade = GetWorld()->SpawnActor<AGrenade>(GrenadeClass, MuzzleLocation, FRotator::ZeroRotator);
if (Grenade)
{
Grenade->GetProjectileMovement()->Velocity = LaunchVelocity;
}
} See Also
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?