I was seeing a video about to create a fps game, i put the same code he put but i does not work to me,

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mate_Dev

This is all the code:

extends Node

export var fire_rate = 0.5
export var clip_size = 5
export var reload_rate = 1

onready var raycast = $"../Head/Camera/RayCast"
var current_ammo = 0
var can_fire = true
var reloading = false

func _process(delta):
	if Input.is_action_just_pressed("primary_fire") and can_fire:
		#fire the weapon
		if current_ammo > 0 and not reloading:
			print("Fired Weapon")
			can_fire = false
			current_ammo -= 1
			check_collision()
			yield(get_tree().create_timer(fire_rate), "timeout")
		
			can_fire = true
		elif not reloading:
			print("Reloading")
			reloading = true
			yield(get_tree().create_timer(fire_rate), "timeout")
			current_ammo = clip_size
			reloading = false
			print("Reload complete")

func check_collision():
	if raycast.is_colliding():
		var collider = raycast.get_collider()
		if collider.is_in_group("Enemies"):
			collider.queue_free()
			print("Killed " + collider.name)

But only the last part:

func check_collision():
if raycast.is_colliding():
var collider = raycast.get_collider()
if collider.is_in_group(“Enemies”):
collider.queue_free()
print("Killed " + collider.name)

When i start the debug and when i shoot it dont detect it and do not print anything

:bust_in_silhouette: Reply From: ichster

You need to check inputs in func _input(event):, not func _process(delta):. Or poll the Input singleton in _physics_process(delta):.

Check this link for good examples: Input examples

P.S. you might want to check raycast in _physics_process(delta):

ichster | 2022-01-30 02:44

This is the video: - Archive - Godot Forum

Mate_Dev | 2022-01-30 19:05

You don’t want to use copied code if you don’t understand how it works. Otherwise, something will go wrong and you will be sitting there wasting a bunch of time scratching your head, and you won’t be able to incorporate what you learned in the future. I am not going to debug a third party’s code snippets so you can move on with it in the interim, because I don’t think you will benefit from that.

If my answer is confusing or badly worded, ask specific clarifying questions.

ichster | 2022-01-31 16:33