How to make an enemy shoot a (top down) shotgun like pattern? (I can't get the bullets' spawn position correctly)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Czselu349

Hi! I’m currently using this solution:
Currently, it doesn’t aims to the player well, and I don’t know how to fix that. It always aims off.
Thecnical stuff:
I’m rotating a vector2 (radius) and spawn the bullets at it’s position. I’m making a regular node (center) look_at() the player, and add it’s rotation to the vector2 (radius)
(The player and the enemy are KinematicBody2D-s and the bullets are Area2D-s wich have their global_position updated.)
I’m using a lot of ideas from this queastion’S 2nd aswer:
https://forum.godotengine.org/12826/spawning-objects-around-a-circle

This is how it aims: (The flame thingy shows the rotation of the center,
but as you can see, the bullets are not spawned at a correct position)
enter image description here

And this is how it should work: (The lines are just helping to visualize)
enter image description here

(If you need any more information, just say it, because I don’t know what else to say.)
BTW the visuals will be worked on after I will fix the main BUGs in the game. (just like this one)

export(int) var shoot_angle = 90  # in degrees
export(int) var numb_of_bullets = 3
export(float) var time_between_shots = 0.5
var radius = Vector2(100, 0)
onready var center = get_node("Center")
var angle_step = shoot_angle / numb_of_bullets

center.look_at(player_node.global_position)

for i in range(numb_of_bullets):
	var spawn_pos = center.global_position + radius.rotated((center.global_rotation / 2) + angle_step * i) # * sign(center.global_rotation / 2))
	
	var node = bullet.instance()
	node.global_position = spawn_pos
	get_parent().add_child(node)
	node.move_direction = global_position.direction_to(node.global_position)

If you need any more information

For starters a bigger image would help. Or a better description of what’s happening: “doesn’t aim […] well” can mean a lot of things. Furthermore it would be helpful to know the node-types you’re using (for the player, enemy and bullet) and how the variables shoot_angle, numb_of_bullets, center and radius are defined.

njamster | 2020-06-23 12:23

Thanks! You’re right…

Czselu349 | 2020-06-23 13:49

Now You can have a look at it :wink:

Czselu349 | 2020-06-23 16:52