projectile is offset

4.3 Godot Version
Replace this line with your Godot version

Question

Im just getting started so maybe I missed something. The problem is, the projectile is offset and spawns in different places depending on the angle I shoot from. I tried changing the values of laser rotation degrees but honestly I feel like the problem isnt in the code. This problem has been haunting me for almost a week now so if anyone could help me I will be very grateful. If you need any more information feel free to ask. I used Marker2D for the projectile spawning point

extends CharacterBody2D
signal laser_shoot(pos, direction)
signal grenade(pos, direction)
var can_laser: bool = true
var can_grenade: bool = true
@onready var weapon_timer = $LaserTimer
@export var PlayerPos = Vector2()

func _process(_delta):
	var direction = Input.get_vector("left", "right", "up", "down")
	velocity = direction * 500
	PlayerPos.x = global_position.x
	PlayerPos.y = global_position.y
	move_and_slide()
	
	look_at(get_global_mouse_position())
	
	var player_direction = (get_global_mouse_position() - position).normalized()
	if Input.is_action_pressed("primary_action") and can_laser:
		$AnimatedSprite2D.play("rifle_shoot")
		$GPUParticles2D.emitting = true
		if weapon_timer.is_stopped():
			weapon_timer.start()
		var laser_makers = $LaserStart.get_children()
		var selected_laser = laser_makers[randi() % laser_makers.size()]
		can_laser = false
		$LaserTimer.start()
		laser_shoot.emit(selected_laser.global_position, player_direction)
extends CharacterBody2D

signal laser_shoot(pos, direction)
signal grenade(pos, direction)

var can_laser: bool = true
var can_grenade: bool = true
@onready var weapon_timer = $LaserTimer
@export var PlayerPos = Vector2()

func _process(_delta):
    # Movement handling
    var direction = Input.get_vector("left", "right", "up", "down")
    velocity = direction * 500
    PlayerPos = global_position  # Simplified assignment
    move_and_slide()
    
    # Rotation handling - add rotation offset
    var mouse_pos = get_global_mouse_position()
    look_at(mouse_pos)
    rotation_degrees += 90  # Adjust this value based on your sprite's natural orientation
    
    # Shooting logic
    if Input.is_action_pressed("primary_action") and can_laser and weapon_timer.is_stopped():
        shoot(mouse_pos)

func shoot(mouse_pos: Vector2):
    $AnimatedSprite2D.play("rifle_shoot")
    $GPUParticles2D.emitting = true
    
    # Get shooting direction
    var player_direction = (mouse_pos - global_position).normalized()
    
    # Get marker position and adjust for rotation
    var laser_makers = $LaserStart.get_children()
    var selected_laser = laser_makers[randi() % laser_makers.size()]
    
    # Start cooldown
    can_laser = false
    weapon_timer.start()
    
    # Emit signal with correct position and direction
    laser_shoot.emit(selected_laser.global_position, player_direction)

# Add this to the scene setup
func _ready():
    # Ensure the LaserStart node is properly positioned relative to the sprite
    # The Marker2D nodes should be positioned where you want the projectiles to spawn
    pass

CharacterBody2D (your player node)
├── AnimatedSprite2D
├── LaserStart
│ ├── Marker2D (spawn point 1)
│ ├── Marker2D (spawn point 2)
│ └── …
├── GPUParticles2D
└── LaserTimer