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)