How to spawn bullets with different angles?

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

How to achieve something like this?

This is my code:

var a = preload(“res://Entities/Enemy/Scenes/EnemyProjectile.tscn”)
var firebolt = a.instance()
if PLAYER_TARGET:
projectilePoint.look_at(player.position)
for i in SPAWN_NUMBER:
projectilePoint.add_child(firebolt)
firebolt.global_transform = projectilePoint.global_transform
firebolt.position.x = OFFSET
firebolt.angle = projectilePoint.angle - ANGLE_OFFSET

:bust_in_silhouette: Reply From: timothybrentwood

This should give you a shotgun like effect:

var a = preload("res://Entities/Enemy/Scenes/EnemyProjectile.tscn")
var add_angle = deg2rad(15) #change this to change the angle, i THINK this has to be in rads, not degrees
if PLAYER_TARGET:
    projectilePoint.lookat(player.position)
for i in SPAWN_NUMBER:
    var firebolt = a.instance()
    projectilePoint.addchild(firebolt)
    firebolt.globaltransform = projectilePoint.globaltransform
    firebolt.position.x = OFFSET
    if i == 0: # shoot straight
        firebolt.angle = projectilePoint.angle - ANGLE_OFFSET
    elif i % 2 == 0: # angle one way
        firebolt.angle = projectilePoint.angle - ANGLE_OFFSET - add_angle
    elif i % 2 == 1: # angle the other way
        firebolt.angle = projectilePoint.angle - ANGLE_OFFSET + add_angle