How to do an asymmetrical "spreading" bullet shot

Godot 4.2.1

Question

Hi, I’m programming a bullet hell/shmup and I wanted to make a shooting pattern for the main character that was like the one in the image (I planned an “upgrade” system for him that goes up to 4).
Example-help-me-pwease

However, I found that what I was trying to do was a bit beyond what I can actually do, I managed to achieve this:

Although it is symmetrical as I wanted, it has a very large spread area, and the packs of bullets also have a large gap between it’s directions, and any change in the number of bullets fired or in the spread variable changes this drastically, making this code unusable right now. I don’t know if I should change the logic of the code completely, or if there is some detail that I’m missing, if anyone can help me with this, I would be grateful.

Here is the simplified code for the character:

func _physics_process(_delta):
	if Input.is_action_pressed("ui_shoot") && $Timer.is_stopped():
		is_shooting()
		$Timer.start() #wait_time = 0.05, oneshot = true

func is_shooting():
	var bullet_num : int = $"%BulletNum".value # Goes from 1 to 4
	var spread : float = deg_to_rad(40)

	var offset : float = spread/bullet_num
	var shot_direction = Vector2(shotDirSlider.value , -1).rotated(-offset*(bullet_num-1)/2) #The X value goes from -1.0 to 1.0

	for i in range(0, bullet_num):
        match  shot_type:
        ...
            ShotType.SPREAD:
	            offset = spread/2
		    	for j in range(0, 2):
		      		var shot = Shot_Placeholder.instantiate()
			    	var pos = global_position - Vector2((bullet_num-1)*10, -70)
			    	call_deferred("add_child", shot)

				shot.position = pos + i*Vector2(20, 0) - shift_mod

				shot.direction = (shot_direction.rotated((offset*i)-(-offset*i))).rotated((-offset*j)).normalized()

And here’s the bullet script:

var direction : Vector2
var speed := 2000

func _process(delta):
	rotation = -direction.angle_to(Vector2.UP)
	position += direction*speed*delta

2024-08-31T22:10:00Z

I ended up solving this with the help of friends, for anyone who ends up coming across this post, I just needed to change the last line.

shot.direction = (shot_direction.rotated((offset*i)-(0.1/2))).normalized()
shot.direction = shot.direction.rotated(0.1*j)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.