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

0 votes

extends Node

class_name weapon

export var firerate = 0.5
export var clip
size = 5
export var reload_rate = 1

onready var raycast = $"./Head/Camera/RayCast"
var currentammo = clipsize
var can_fire = true
var reloading = false

func process(delta):
if Input.is
actionjustpressed("primaryfire") and canfire:
if currentammo > 0 and not reloading:
print("Fired weapon")
can
fire = false
currentammo -= 1
check
collision()
yield(gettree().createtimer(fire_rate), "timeout")

        can_fire = true
    elif not reloading:
        print("Reloading")
        reloading = true
        yield(get_tree().create_timer(reload_rate), "timeout")
        current_ammo = clip_size
        reloading = false
        print("Reload complete")

func checkcollision():
if raycast.is
colliding():
var collider = raycast.getcollider()
if collider.is
ingroup("Enemies"):
collider.queue
free()
print("Killed" + collider.name)

Godot version 3.4.2
in Engine by (12 points)

what does the error say?

Two things to help those trying to help you...

  1. Format your code in the post - it's hard to read otherwise. To do that, edit your post, select the text that is the code, and press the { } "Code Sample" button in the editor's toolbar.
  2. You mention you're getting an error. Please post the error itself and any other relevant info you might have.

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.