feat: implement foundational weapon systems, including hitscan and projectile base classes, reload mechanics, and player movement/camera integration.
This commit is contained in:
@@ -11,6 +11,7 @@ class_name BaseProjectileWeapon
|
||||
@export var max_range: float = 200.0
|
||||
@export var automatic: bool = true
|
||||
@export var spread_angle: float = 0.01
|
||||
@export var recoil_amplitude: float = 0.05
|
||||
|
||||
@export var projectile_speed: float = 50.0
|
||||
@export var projectile_gravity: float = 0.0
|
||||
@@ -45,15 +46,19 @@ func _process(delta: float) -> void:
|
||||
fire_cooldown -= delta
|
||||
|
||||
if reloading:
|
||||
reload_timer -= delta
|
||||
var spin_speed = (PI * 2.0) / reload_time
|
||||
var spin_speed = PI * 4.0
|
||||
model_root.rotation.x += spin_speed * delta
|
||||
|
||||
if reload_timer <= 0.0:
|
||||
current_ammo = max_ammo
|
||||
reloading = false
|
||||
model_root.rotation.x = 0.0
|
||||
print(weapon_name, " Reloaded!")
|
||||
if reload_timer > 0.0:
|
||||
reload_timer -= delta
|
||||
else:
|
||||
# Continue the loop until facing normal direction (multiples of 2 PI)
|
||||
var target_rot = ceil(model_root.rotation.x / (PI * 2.0)) * (PI * 2.0)
|
||||
if target_rot - model_root.rotation.x < spin_speed * delta * 1.5:
|
||||
current_ammo = max_ammo
|
||||
reloading = false
|
||||
model_root.rotation.x = 0.0
|
||||
print(weapon_name, " Reloaded!")
|
||||
|
||||
elif automatic and is_firing and fire_cooldown <= 0.0 and current_ammo > 0:
|
||||
_fire()
|
||||
@@ -92,6 +97,9 @@ func _fire() -> void:
|
||||
_shoot_projectile()
|
||||
_play_muzzle_flash()
|
||||
|
||||
if get_parent() and get_parent().has_method("add_recoil"):
|
||||
get_parent().add_recoil(recoil_amplitude, randf_range(-recoil_amplitude * 0.5, recoil_amplitude * 0.5))
|
||||
|
||||
if fire_sound:
|
||||
fire_sound.pitch_scale = 1.0 + randf_range(-0.05, 0.05)
|
||||
fire_sound.play()
|
||||
|
||||
Reference in New Issue
Block a user