BallisticSolutions 6.1.0
dotnet add package BallisticSolutions --version 6.1.0
NuGet\Install-Package BallisticSolutions -Version 6.1.0
<PackageReference Include="BallisticSolutions" Version="6.1.0" />
<PackageVersion Include="BallisticSolutions" Version="6.1.0" />
<PackageReference Include="BallisticSolutions" />
paket add BallisticSolutions --version 6.1.0
#r "nuget: BallisticSolutions, 6.1.0"
#:package BallisticSolutions@6.1.0
#addin nuget:?package=BallisticSolutions&version=6.1.0
#tool nuget:?package=BallisticSolutions&version=6.1.0
BallisticSolutions (C#)
Table of Contents
Installation & Dependencies
Two packages are available depending on your project type:
| Package | Vector types |
|---|---|
| BallisticSolutions | System.Numerics.Vector* |
| BallisticSolutions.Godot | Godot.Vector* |
Installation
Option 1: NuGet Package (Recommended)
Search for package in the NuGet manager.
Or add to your .csproj:
<ItemGroup>
<PackageReference Include="BallisticSolutions" Version="*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BallisticSolutions.Godot" Version="*" />
</ItemGroup>
Option 2: DLL (Godot addon)
Add to your .csproj:
<ItemGroup>
<Reference Include="BallisticSolutions.Godot">
<HintPath>addons\BallisticSolutions.Godot\BallisticSolutions.Godot.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics">
<HintPath>addons\BallisticSolutions.Godot\MathNet.Numerics.dll</HintPath>
</Reference>
</ItemGroup>
Dependencies
BallisticSolutions.Godot:
Example
using Godot;
using BallisticSolutions.Godot.BsSolvers.BsVelocity;
// ...
[Export]
public PackedScene ProjectileScene { get; set; }
[Export]
public float ProjectileSpeed { get; set; } = 200;
[Export]
public Vector2 ProjectileAcceleration { get; set; }
public void Shoot(Target2D target) {
Vector2 toTarget = target.GlobalPosition - GlobalPosition;
Vector2 velocity = BsVelocity2D.Best(
ProjectileSpeed,
toTarget,
target.Velocity,
ProjectileAcceleration,
target.Acceleration
);
if (float.IsNaN(velocity.X)) {
GD.Print("Impossible to hit the target");
return;
}
var newProjectile = ProjectileScene.Instantiate<Projectile2D>();
newProjectile.GlobalPosition = GlobalPosition;
newProjectile.Velocity = velocity;
newProjectile.Acceleration = ProjectileAcceleration;
GetParent().AddChild(newProjectile);
}
Reference
For the complete documentation, refer to the generated XML documentation.
*D suffix denotes 2D, 3D, or 4D variants — BsTime*D stands for BsTime2D, BsTime3D, and BsTime4D. Each variant uses the corresponding Vector* type (Vector2, Vector3, Vector4). All variants share the same API.
BsSolution<T>
Abstract base class representing a ballistic solution. T is a floating-point numeric type (e.g., float, double).
| Property | Type | Description |
|---|---|---|
Time |
T |
Interception time. |
Position |
Vector* |
Impact position relative to the projectile origin. |
DistanceToPosition |
float |
Distance to the impact position. |
DirectionToPosition |
Vector* |
Direction to the impact position. |
ProjectileVelocity |
Vector* |
Required firing velocity. |
ProjectileSpeed |
float |
Projectile speed. |
ProjectileDirection |
Vector* |
Projectile direction. |
ToTarget |
Vector* |
Vector from shooter to target at t = 0. |
DistanceToTarget |
float |
Distance to target at t = 0. |
DirectionToTarget |
Vector* |
Direction to target at t = 0. |
TargetVelocity |
Vector* |
Target velocity at t = 0. |
TargetSpeed |
float |
Target speed. |
TargetDirection |
Vector* |
Target direction. |
ProjectileAcceleration |
Vector* |
Projectile acceleration. |
TargetAcceleration |
Vector* |
Target acceleration. |
BsSolution*D
BsSolution*D<T>? Best<T>(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest valid solution, or null if interception is impossible.
BsSolution*D<T>? Best<T>(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest valid solution, or null if interception is impossible.
BsSolution*D<T>[] All<T>(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid solutions sorted by interception time. Empty array if impossible.
BsSolution*D<T>[] All<T>(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid solutions sorted by interception time. Empty array if impossible.
BsPosition*D
Vector* Displacement<T>(T time, Vector* velocity, Vector* acceleration = default)
Returns: displacement under constant acceleration.
Vector* Position<T>(Vector* position, T time, Vector* velocity, Vector* acceleration = default)
Returns: position after elapsed time under constant acceleration.
Vector* Best(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest valid impact position. Returns a NaN vector if impossible.
Vector* Best(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest valid impact position. Returns a NaN vector if impossible.
Vector*[] All(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid impact positions. Empty array if impossible.
Vector*[] All(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid impact positions. Empty array if impossible.
BsTime*D
T Best<T>(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest interception time (t ≥ 0). Returns NaN if impossible.
T Best<T>(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest interception time (t ≥ 0). Returns NaN if impossible.
T[] All<T>(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid interception times sorted ascending. Empty array if impossible.
T[] All<T>(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid interception times sorted ascending. Empty array if impossible.
BsVelocity*D
Vector* Velocity<T>(T time, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the firing velocity required to hit the target at the given time.
Vector* Best(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest valid firing velocity. Returns a NaN vector if impossible.
Vector* Best(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: the earliest valid firing velocity. Returns a NaN vector if impossible.
Vector*[] All(float projectileSpeed, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid firing velocities. Empty array if impossible.
Vector*[] All(Vector* projectileDirection, Vector* toTarget, Vector* targetVelocity = default, Vector* projectileAcceleration = default, Vector* targetAcceleration = default)
Returns: all valid firing velocities. Empty array if impossible.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- MathNet.Numerics (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.