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 checkcollision():
if raycast.iscolliding():
var collider = raycast.getcollider()
if collider.isingroup("Enemies"):
collider.queuefree()
print("Killed " + collider.name)
When i start the debug and when i shoot it dont detect it and do not print anything