Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser

Quick Information

Ballistic deflection calculator is a tool for calculating the shot vector considering speeds and accelerations for Godot.Example:@export var projectile_packed_scene: PackedScenevar projectile_speed: float = 200var projectile_acceleration: Vector2 = Vector2.ZEROfunc shoot(target: Target2D) -> void:var to_target: Vector2 = target.global_position - global_positionvar projectile_velocities: Array[Vector2] = Bdc.velocities_vector2(bullet_speed, to_target, target.velocity, projectile_acceleration, target.acceleration)if projectile_velocities.size() == 0:print("Impossible to hit the target")returnvar new_projectile: Projectile2D = projectile_packed_scene.instantiate()new_projectile.global_position = global_positionnew_projectile.velocity = bullet_velocities[0]new_projectile.acceleration = projectile_accelerationget_parent().add_child(new_projectile)
BDC - Ballistic Deflection Calculator
Ballistic deflection calculator is a tool for calculating the shot vector considering speeds and accelerations for Godot.
Methods
GDScipt
Bdc
# Times To Hit
Array[float] times_to_hit(projectile_speed: float, to_target: Variant, target_velocity: Variant = Vector4.ZERO, projectile_acceleration: Variant = Vector4.ZERO, target_acceleration: Variant = Vector4.ZERO) static
Array[float] times_to_hit_vector2(projectile_speed: float, to_target: Vector2, target_velocity: Vector2 = Vector2.ZERO, projectile_acceleration: Vector2 = Vector2.ZERO, target_acceleration: Vector2 = Vector2.ZERO) static
Array[float] times_to_hit_vector3(projectile_speed: float, to_target: Vector3, target_velocity: Vector3 = Vector3.ZERO, projectile_acceleration: Vector3 = Vector3.ZERO, target_acceleration: Vector3 = Vector3.ZERO) static
Array[float] times_to_hit_vector4(projectile_speed: float, to_target: Vector4, target_velocity: Vector4 = Vector4.ZERO, projectile_acceleration: Vector4 = Vector4.ZERO, target_acceleration: Vector4 = Vector4.ZERO) static
# Velocities
Array velocities(projectile_speed: float, to_target: Variant, target_velocity: Variant = Vector4.ZERO, projectile_acceleration: Variant = Vector4.ZERO, target_acceleration: Variant = Vector4.ZERO) static
Array[Vector2] velocities_vector2(projectile_speed: float, to_target: Vector2, target_velocity: Vector2 = Vector2.ZERO, projectile_acceleration: Vector2 = Vector2.ZERO, target_acceleration: Vector2 = Vector2.ZERO) static
Array[Vector3] velocities_vector3(projectile_speed: float, to_target: Vector3, target_velocity: Vector3 = Vector3.ZERO, projectile_acceleration: Vector3 = Vector3.ZERO, target_acceleration: Vector3 = Vector3.ZERO) static
Array[Vector4] velocities_vector4(projectile_speed: float, to_target: Vector4, target_velocity: Vector4 = Vector4.ZERO, projectile_acceleration: Vector4 = Vector4.ZERO, target_acceleration: Vector4 = Vector4.ZERO) static
# Velocity From Time To Hit
Variant velocity_from_time_to_hit(time_to_hit: float, to_target: Variant, target_velocity: Variant = Vector4.ZERO, projectile_acceleration: Variant = Vector4.ZERO, target_acceleration: Variant = Vector4.ZERO) static
Vector2 velocity_from_time_to_hit_vector2(time_to_hit: float, to_target: Vector2, target_velocity: Vector2 = Vector2.ZERO, projectile_acceleration: Vector2 = Vector2.ZERO, target_acceleration: Vector2 = Vector2.ZERO) static
Vector3 velocity_from_time_to_hit_vector3(time_to_hit: float, to_target: Vector3, target_velocity: Vector3 = Vector3.ZERO, projectile_acceleration: Vector3 = Vector3.ZERO, target_acceleration: Vector3 = Vector3.ZERO) static
Vector4 velocity_from_time_to_hit_vector4(time_to_hit: float, to_target: Vector4, target_velocity: Vector4 = Vector4.ZERO, projectile_acceleration: Vector4 = Vector4.ZERO, target_acceleration: Vector4 = Vector4.ZERO) static
C#
BallisticDeflectionCalculator.Bdc
// Times To Hit
T[] TimesToHit<T>(T projectileSpeed, Vector2 toTarget, Vector2 targetVelocity = default, Vector2 projectileAcceleration = default, Vector2 targetAcceleration = default) where T : IFloatingPoint<T>;
T[] TimesToHit<T>(T projectileSpeed, Vector3 toTarget, Vector3 targetVelocity = default, Vector3 projectileAcceleration = default, Vector3 targetAcceleration = default) where T : IFloatingPoint<T>;
T[] TimesToHit<T>(T projectileSpeed, Vector4 toTarget, Vector4 targetVelocity = default, Vector4 projectileAcceleration = default, Vector4 targetAcceleration = default) where T : IFloatingPoint<T>;
// Velocities
Vector2[] Velocities<T>(T projectileSpeed, Vector2 toTarget, Vector2 targetVelocity = default, Vector2 projectileAcceleration = default, Vector2 targetAcceleration = default) where T : IFloatingPoint<T>;
Vector3[] Velocities<T>(T projectileSpeed, Vector3 toTarget, Vector3 targetVelocity = default, Vector3 projectileAcceleration = default, Vector3 targetAcceleration = default) where T : IFloatingPoint<T>;
Vector4[] Velocities<T>(T projectileSpeed, Vector4 toTarget, Vector4 targetVelocity = default, Vector4 projectileAcceleration = default, Vector4 targetAcceleration = default) where T : IFloatingPoint<T>;
// Velocity From Time To Hit
Vector2 VelocityFromTimeToHit<T>(T timeToHit, Vector2 toTarget, Vector2 targetVelocity = default, Vector2 projectileAcceleration = default, Vector2 targetAcceleration = default) where T : IFloatingPoint<T>;
Vector3 VelocityFromTimeToHit<T>(T timeToHit, Vector3 toTarget, Vector3 targetVelocity = default, Vector3 projectileAcceleration = default, Vector3 targetAcceleration = default) where T : IFloatingPoint<T>;
Vector4 VelocityFromTimeToHit<T>(T timeToHit, Vector4 toTarget, Vector2 targetVelocity = default, Vector4 projectileAcceleration = default, Vector4 targetAcceleration = default) where T : IFloatingPoint<T>;
Example
GDScipt
@export var projectile_packed_scene: PackedScene
var projectile_speed: float = 200
var projectile_acceleration: Vector2 = Vector2.ZERO
func shoot(target: Target2D) -> void:
var to_target: Vector2 = target.global_position - global_position
var projectile_velocities: Array[Vector2] = Bdc.velocities_vector2(bullet_speed, to_target, target.velocity, projectile_acceleration, target.acceleration)
if projectile_velocities.size() == 0:
print("Impossible to hit the target")
return
var new_projectile: Projectile2D = projectile_packed_scene.instantiate()
new_projectile.global_position = global_position
new_projectile.velocity = bullet_velocities[0]
new_projectile.acceleration = projectile_acceleration
get_parent().add_child(new_projectile)
C#
using Godot;
using BallisticDeflectionCalculator;
// ...
[Export]
public PackedScene? ProjectilePackedScene { get; set; }
public float ProjectileSpeed { get; set; } = 200;
public Vector2 ProjectileAcceleration { get; set; } = Vector2.Zero;
public void Shoot(Target2D target) {
Vector2 toTarget = target.GlobalPosition - GlobalPosition;
Vector2[] projectileVelocities = Bdc.Velocities(ProjectileSpeed, toTarget, target.Velocity, ProjectileAcceleration, target.Acceleration);
if (projectileVelocities.Length == 0) {
GD.Print("Impossible to hit the target");
return;
}
Projectile2D newProjectile = ProjectilePackedScene.Instantiate<Projectile2D>();
newProjectile.GlobalPosition = GlobalPosition;
newProjectile.Velocity = projectileVelocities[0];
newProjectile.Acceleration = ProjectileAcceleration;
GetParent().AddChild(newProjectile);
}
Adding the Ballistic Deflection Calculator
to your C# project
Option 1: Using IDE
To use this library, you need to reference the compiled .dll
file in your project.
- Right-click on your project in Solution Explorer -> Add -> Project Reference….
- Select Browse… and choose the
BallisticDeflectionCalculator.dll
file. - Install MathNet.Numerics Or choose the
MathNet.Numerics.dll
file similarly to step 2. - Confirm and rebuild your project.
- Add the namespace in your code:
using BallisticDeflectionCalculator;
Option 2: Edit the .csproj file directly
- Add a
<Reference>
entry for theBallisticDeflectionCalculator.dll
in<ItemGroup>
<ItemGroup>
<Reference Include="BallisticDeflectionCalculator">
<HintPath>addons\BallisticDeflectionCalculatorCSharp\BallisticDeflectionCalculator.dll</HintPath>
</Reference>
</ItemGroup>
- Add NuGet dependencies: MathNet.Numerics
<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
</ItemGroup>
- Or Add a
<Reference>
entry for theMathNet.Numerics.dll
in<ItemGroup>
<ItemGroup>
<Reference Include="MathNet.Numerics">
<HintPath>addons\BallisticDeflectionCalculatorCSharp\MathNet.Numerics.dll</HintPath>
</Reference>
</ItemGroup>
Demo
You can test the addon using the included demo scene.
Dependencies
- GDScript version:
- C# version:
How it works?
Ballistic deflection calculator is a tool for calculating the shot vector considering speeds and accelerations for Godot.
Example:
@export var projectile_packed_scene: PackedScene
var projectile_speed: float = 200
var projectile_acceleration: Vector2 = Vector2.ZERO
func shoot(target: Target2D) -> void:
var to_target: Vector2 = target.global_position - global_position
var projectile_velocities: Array[Vector2] = Bdc.velocities_vector2(bullet_speed, to_target, target.velocity, projectile_acceleration, target.acceleration)
if projectile_velocities.size() == 0:
print("Impossible to hit the target")
return
var new_projectile: Projectile2D = projectile_packed_scene.instantiate()
new_projectile.global_position = global_position
new_projectile.velocity = bullet_velocities[0]
new_projectile.acceleration = projectile_acceleration
get_parent().add_child(new_projectile)
Reviews
Quick Information

Ballistic deflection calculator is a tool for calculating the shot vector considering speeds and accelerations for Godot.Example:@export var projectile_packed_scene: PackedScenevar projectile_speed: float = 200var projectile_acceleration: Vector2 = Vector2.ZEROfunc shoot(target: Target2D) -> void:var to_target: Vector2 = target.global_position - global_positionvar projectile_velocities: Array[Vector2] = Bdc.velocities_vector2(bullet_speed, to_target, target.velocity, projectile_acceleration, target.acceleration)if projectile_velocities.size() == 0:print("Impossible to hit the target")returnvar new_projectile: Projectile2D = projectile_packed_scene.instantiate()new_projectile.global_position = global_positionnew_projectile.velocity = bullet_velocities[0]new_projectile.acceleration = projectile_accelerationget_parent().add_child(new_projectile)