
Ballistic Solutions (GDScript, C#) 4.0.0 Scripts 4.0 Community
Submitted by user neclor; MIT; 2025-09-01
Library for calculating interception times, impact positions, and firing vectors, taking into account the velocities and accelerations of both projectile and target.
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 velocity: Vector2 = Bsc.best_firing_velocity_vector2(projectile_speed, to_target, target.velocity, projectile_acceleration, target.acceleration)
if is_nan(velocity.x):
print("Impossible to hit the target")
return
var new_projectile: Projectile2D = projectile_packed_scene.instantiate()
new_projectile.global_position = global_position
new_projectile.velocity = velocity
new_projectile.acceleration = projectile_acceleration
get_parent().add_child(new_projectile)
View files Download Submit an issue Recent Edits