Okay so im trying to code a weapon and projectile managing system, for this i've made the weapons send a signal containing the information of the projectile such as how much it should spread or the amount of projectiles fired per shot(to make a shotgun for instance). The following code on the node is in charge off spawning said projectiles, it works just fine when firing single projectiles per shot but once i try to spawn more than one projectile per shot and iterate through the code all of the bullets spawned have the exact same direction and rotation, any ideas of why this may be? Thanks in advance!
extends Node
var rng = RandomNumberGenerator.new()
func handle_projectile_spawn(projectile, position, direction, projectile_amount, projectile_spread_angle):
for i in projectile_amount:
var spread_angle = deg2rad(projectile_spread_angle)/2
direction = direction.angle()
direction = rng.randf_range((direction+spread_angle), (direction-spread_angle))
direction = Vector2(cos(direction), sin(direction))
add_child(projectile)
projectile.global_position = position
projectile.set_direction(direction)
print("bullet ", i, " fired, direction ", direction)