Projectiles not rotating as intended

Godot Version

4.2.2

Question

So I have made a script that instantiates my projectile and rotates it, but it only rotates the direction it flies in and never the projectile on its own, why? Could someone help me understand this?

my projectile script:

extends Node2D

@export var default_projectile_stats : ProjectileStats

@export var proj_area : Area2D

var direction : Vector2

func _ready():
	direction = (get_global_mouse_position() - position).normalized()

func _physics_process(delta):
	proj_area.position += direction * default_projectile_stats.projectile_speed * delta

my script responsible for shooting:

class_name Shoot
extends Node

@export var proj_stats : ProjectileStats
@export var default_projectile_scene : PackedScene
@export var pivot : Marker2D
@export var muzzle : Marker2D
@export var fire_rate : Timer

var fire_rate_timer_value : float
var fire_rate_cd : bool = false


var projectile_angles : Array[float]

var old_projectile_amount

func _ready():
	projectile_spread()
	old_projectile_amount = proj_stats.projectile_amount

func _process(delta):
	if old_projectile_amount != proj_stats.projectile_amount:
		projectile_spread()
	
	if Input.is_action_just_pressed("shoot") && pivot.mouse_distance > 20 && !fire_rate_cd:
		projectile_spread()
		_shoot_proj()
		fire_rate.start(proj_stats.fire_rate)
		fire_rate_cd = true

func _on_fire_rate_timeout():
	fire_rate_cd = false

func _shoot_proj():
	for i in range(proj_stats.projectile_amount):
		var proj = default_projectile_scene.instantiate()
		proj.global_position = muzzle.global_position
		proj.rotation = deg_to_rad(projectile_angles[i])
		print(proj.rotation_degrees)
		add_child(proj)

func projectile_spread():
	var total_angle = (proj_stats.projectile_amount - 1) * proj_stats.spread_angle
	var start_angle
	if proj_stats.projectile_amount > 1:
		start_angle = -(total_angle / 2)
	else:
		start_angle = 0
	
	for i in range(proj_stats.projectile_amount):
		projectile_angles.append(start_angle + i * proj_stats.spread_angle)

shooting left or right works, but any other direction just doesn’t

I’m not sure if I understand the problem. What do you expect to happen? What happens instead? Do the screenshots show any unwanted behavior? What do you mean by “any other direction just doesn’t”?

1 Like