Projectile not lining up with Marker2D node

Godot Version

4.5

Question

When I shoot my projectile, it doesn’t exactly line up with my marker2D. Is there anything wrong with my player script?

extends CharacterBody2D

@export var speed := 200
@export var projectile_scene: PackedScene

func _physics_process(delta):
var input_vector = Vector2.ZERO

if Input.is_action_pressed("right"):
	input_vector.x += 1
if Input.is_action_pressed("left"):
	input_vector.x -= 1
if Input.is_action_pressed("down"):
	input_vector.y += 1
if Input.is_action_pressed("up"):
	input_vector.y -= 1

input_vector = input_vector.normalized()

velocity = input_vector * speed
move_and_slide()

func _process(delta):
if Input.is_action_just_pressed(“shoot”):
shoot_projectile()

func shoot_projectile():
var projectile = projectile_scene.instantiate()
projectile.position = $Muzzle.global_position

# Determine direction based on the character facing


get_tree().current_scene.add_child(projectile)


Set the position after you’ve added the node to the scene tree. You also might want to assign to global_position instead of position, although in this case it probably won’t make a difference.

I had a similar problem and the problem was that my projectile scene really centered so it spawned a bit off center