Skip to content

Capmare/Ballistic-prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Ballistic Prediction in Unreal Engine: Iterative, RK4, and Analytical Methods

I made this project to simulate a scenario of a anti-aircraft ballistic shooter The testing parameters are scaled down due to CPU performance

This document aims to explain three ballistic aiming techniques.

  • Iterative
  • Iterative RK4
  • Analytical

Testing parameters

View cone angle: 45 Degrees Max view distance: 6km Max shooting distance: 6km Shoot interval: 0.5s Max tolerance: 0.005 Iterations: 10000

Iterative Ballistic Solution

Purpose

Estimate the required velocity vector and use the Newton-Raphson refinement to correct the velocity error

Equation

FVector LaunchVelocity = (Displacement - 0.5f * Gravity * t * t) / t; 

$$ \vec{v} = \frac{\vec{p} - 0.5 \cdot \vec{g} \cdot t^2}{t} $$

Usage

Moving or accelerating targets, mid-range to long-range shots, realistic lead targeting

Strengths

  • Moderate CPU usage
  • Good for moving targets

Weaknesses

  • Might fail at long distances

Long range data

2000-3000m Distance

Iterative Ballistic Solution Diagram

Close range data

500-1200m Distance

Iterative Ballistic Solution Diagram Close

Iterative RK4

Purpose

Improve iterative acurracy using the Runge-Kutta integration

Equation

	auto Acc = [&](const FVector& /*pos*/, const FVector& /*vel*/) -> FVector
	{
		return Acceleration; // constant gravity
	};

	FVector k1v = Acc(Position, Velocity);
	FVector k1x = Velocity;

	FVector k2v = Acc(Position + 0.5f * k1x * DeltaTime, Velocity + 0.5f * k1v * DeltaTime);
	FVector k2x = Velocity + 0.5f * k1v * DeltaTime;

	FVector k3v = Acc(Position + 0.5f * k2x * DeltaTime, Velocity + 0.5f * k2v * DeltaTime);
	FVector k3x = Velocity + 0.5f * k2v * DeltaTime;

	FVector k4v = Acc(Position + k3x * DeltaTime, Velocity + k3v * DeltaTime);
	FVector k4x = Velocity + k3v * DeltaTime;

	OutNewPosition = Position + (DeltaTime / 6.0f) * (k1x + 2.f * k2x + 2.f * k3x + k4x);
	OutNewVelocity = Velocity + (DeltaTime / 6.0f) * (k1v + 2.f * k2v + 2.f * k3v + k4v);

$$ y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) \cdot dt $$

Usage

Very accurate prediction, compares the predicted impact point to the target predicted position. Adjusts t until the simulated projectile matches the moving target with a tolerance

Strengths

  • More accurate curves
  • Works well with gravity

Weaknesses

  • Might fail at long distances, but less than the normal iterative method
  • Heavy CPU usage
  • Sensitive to tolerance settings and time step

Long range data

2000-3000m Distance

Iterative RK4 Solution Diagram

Close range data

500-1200m Distance

Iterative RK4 Solution Diagram Close

Analytical

Purpose

Cheap computation of the launch angle

Equation

float SpeedSq = ProjectileSpeed * ProjectileSpeed;
float GravityMag = -GravityZ;

float Discriminant = SpeedSq * SpeedSq - GravityMag * (GravityMag * DistXZ * DistXZ + 2 * DeltaZ * SpeedSq);
float SqrtDisc = FMath::Sqrt(Discriminant);

float AngleNumerator = SpeedSq - SqrtDisc; // (or + for high arc)
float AngleDenominator = GravityMag * DistXZ;

float TanTheta = AngleNumerator / AngleDenominator;
float Theta = FMath::Atan(TanTheta);

$$ \tan(\theta) = \frac{v^2 \pm \sqrt{v^4 - g(gx^2 + 2yv^2)}}{gx} $$

Usage

Static targets and known positions

Strengths

  • Acurate curves
  • Cheap CPU usage

Weaknesses

  • Will fail at medium-long range
  • Does not account for velocity or acceleration

Long range data

2000-3000m Distance

Analytical Solution Diagram

Close range data

500-1200m Distance

Analytical Solution Diagram Close

Conclusion

All 3 algorithms are good for different situations. The testing of this was very small and requieres more testing and different situations for more accurate results, but from the current testing we can deduce the following.

  • The Iterative method is good at handling moving targets and it is cheap for the CPU to handle but has issues with its curve trajectory
  • The RK4 Iterative method is good at handling moving target and its curve is way more accurate than the normal iterative method but requieres more CPU power
  • The Analytical method is bad with moving targets and should be used for static targets and known positions, but is very cheap on the CPU

Used resources

https://en.wikipedia.org/wiki/Projectile_motion
https://en.wikipedia.org/wiki/Newton%27s_method https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods https://gamedev.stackexchange.com/questions/53552/how-can-i-find-a-projectiles-launch-angle

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors