open-strike-2/scenes/weapon/guns/ak/bullet_spread.gd
2025-02-04 18:35:44 +03:00

36 lines
998 B
GDScript

class_name BulletSpread extends Resource
@export var max_spread: float = 5.0
@export var spread_increase_per_shot: float = 0.5
var current_spread: float = 0.0
var shot_count: int = 0
var spread_y : float = 0
var spread_x: float = 0
var last_y_spread: float = 0 # remember y cord for 9th shot
func reset_spread() -> void:
current_spread = 0.0
shot_count = 0
# To get offset for current shot
func get_spread_offset() -> Vector3:
# Increasing spread after each shot
current_spread = min(current_spread + spread_increase_per_shot, max_spread)
shot_count += 1
# If its a 1 shot
if shot_count == 1:
return Vector3.ZERO
if shot_count < 10:
spread_x = randf_range(-current_spread, current_spread) * (shot_count - 1)
spread_y = current_spread * (shot_count - 1)
if shot_count == 9: last_y_spread = spread_y
else:
spread_x = randf_range(-current_spread, current_spread) * 10
spread_y = randf_range(last_y_spread - 10, last_y_spread + 10)
return Vector3(spread_x, spread_y, 0)