The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

–1 vote

https://www.youtube.com/watch?v=Y_2oiLjOx54&t=1025s&ab_channel=CodewithTom

In minute 18:10, i do the same as he did but it dont works to me:

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:
        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)
in Engine by (17 points)

Thanks for the tip but i just solve it.

I am aware . It's best for you to start with simple games first. I started the same way. Just a suggestion.

In what way doesn't it work?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.