Can you help me with tutter? My turret doesn't shoot

Godot Version

4

Question

`I’m trying to make a turret that will shoot if the player enters a certain area but it does not shoot

`
@onready var ray_cast = $aim
@onready var timer = $recharging
@export var ammo : PackedScene

var target

func _ready():
target = get_parent().find_child(“player”)

func _physics_process(_delta):
_aim()
_check_player_collision()

func _aim():
ray_cast.target_position = to_local(target.position)

func _check_player_collision():
if ray_cast.get_collider() == target and timer.is_stopped():
timer.start()
elif ray_cast.get_collider() != target and not timer.is_stopped():
timer.stop()

func _on_timer_timeout():
_shoot()
print(“s”)

func _shoot():
var bullet = ammo.instantiate()
bullet.position = position
bullet.direction = (ray_cast.target_position).normalized()
get_tree().current_scene.add_child(bullet)
`

Try using an Area instead of pointing a raycast at the target. The to_local function is for converting global coordinates to local.

func _on_area_body_entered(body):
    if body.name == "player":
        timer.start()

func _on_area_body_exited(body):
    if body.name == "player":
        timer.stop()