Updated the bullet spawning position to beging from the sprite height

modified by the weapon's origin variable.
This commit is contained in:
Henry Faber 2026-06-28 08:05:30 +01:00
parent 64e685a3c1
commit 9554af183c
7 changed files with 38 additions and 27 deletions

View file

@ -17,6 +17,19 @@ func shoot():
player.travel = 0.0
func _get_spawn_position(weapon_data: WeaponShot) -> Vector2:
# Determine sprite height with a region_rect → texture fallback.
var sprite_height: float = 0.0
if ship.region_rect.has_area():
sprite_height = ship.region_rect.size.y
else:
sprite_height = ship.texture.get_height()
# Top edge of the sprite in world space, then offset by origin.
var top_edge = ship.global_position.y - (sprite_height / 2.0)
return Vector2(ship.global_position.x, top_edge + weapon_data.origin)
# Standard projectile logic (delegates to WeaponFireHelper)
func _shoot_standard(weapon_data: WeaponShot, current_time: float):
var total_projectiles: int = weapon_data.projectiles
@ -26,8 +39,8 @@ func _shoot_standard(weapon_data: WeaponShot, current_time: float):
var bullet := weapon_data.bullet_scene.instantiate() as Area2D
get_tree().root.add_child(bullet)
# Delegate math to the helper, with spawn position offset by weapon origin
var spawn_position = ship.global_position + weapon_data.origin
# Delegate math to the helper
var spawn_position = _get_spawn_position(weapon_data)
var props = fire_helper.compute_standard_props(weapon_data, b, spawn_position, current_time)
bullet.position = props.position
bullet.angle = props.angle
@ -50,7 +63,7 @@ func _shoot_grouped(weapon_data: WeaponShot, current_time: float):
get_tree().root.add_child(bullet)
# Apply computed properties for the original bullet
var spawn_position = ship.global_position + weapon_data.origin
var spawn_position = _get_spawn_position(weapon_data)
var props = fire_helper.compute_grouped_props(group, weapon_data, b, spawn_position, current_time, false)
bullet.position = props.position
bullet.angle = props.angle
@ -66,7 +79,7 @@ func _shoot_grouped(weapon_data: WeaponShot, current_time: float):
get_tree().root.add_child(mirror_bullet)
# Apply computed properties for the mirrored bullet
var mirror_spawn = ship.global_position + weapon_data.origin
var mirror_spawn = _get_spawn_position(weapon_data)
var mirror_props = fire_helper.compute_grouped_props(group, weapon_data, b, mirror_spawn, current_time, true)
mirror_bullet.position = mirror_props.position
mirror_bullet.angle = mirror_props.angle