0 votes

Okay, so I have code for switching weapons but, I don’t know how to integrate it with code that would make the player pick up weapons (Doom-Style). The player is already holding all the guns, while all weapon switching really does is control which gun is visible and functioning. Just like the weapon switching code, I only want to create the illusion of picking up weapons as oppose to actually picking up anything. The goal would be to have a (preferably Boolean) variable in each weapon that represents whether or not the weapon has been picked up, and then have the weapon switching code deliberately skip weapons that haven’t been picked up. All the weapon pick ups would actually do is toggle the variable in the weapons that determined which weapon is picked up. Now even though I know what I want in theory, I have a hard time implementing it in practice. I’ve tried while loops, only for that to cause my game to crash. Does anyone have any idea how I can impliment the weapon pick up machanic I want?

Here is the code for my weapon switching:

func _input(event):
    if event is InputEventMouseButton:#Without this line of code(if event is InputEventMouseButton), mouse buttons buttons wouldn't work.
        if Input.is_action_just_pressed("mouse_wheel_up") and not equip:#Input for scrolling the mouse wheel up.
            change_weapon(wrapi(weapon_index + 1,0,max_weapon+1))
        elif Input.is_action_just_pressed("mouse_wheel_down") and not equip:#Input for scrolling the mouse wheel down.
            change_weapon(wrapi(weapon_index - 1,0,max_weapon+1))

func _process(delta):
    current_weapon = inventory[weapon_index]
    if Input.is_action_just_pressed("weapon1") and weapon_index != 0 and not equip:
        change_weapon(0)
    elif Input.is_action_just_pressed("weapon2") and weapon_index != 1 and not equip:
        change_weapon(1)
    elif Input.is_action_just_pressed("weapon3") and weapon_index != 2 and not equip:
        change_weapon(2)
    elif Input.is_action_just_pressed("weapon4") and weapon_index != 3 and not equip:
        change_weapon(3)
    for i in inventory:
        if i == current_weapon:
            if equip == false:
                i.in_use()

func equip_anim(anim):#Function for equip/enquip animation
    anim_player.playback_speed = 2;anim

func change_weapon(my_weapon_index):
    if my_weapon_index <= max_weapon:#This helps to change weapons!
            equip = true;equip_anim(anim_player.play_backwards(equip_anim[weapon_index]))
            yield(anim_player,"animation_finished")
            weapon_index = my_weapon_index
            equip_anim(anim_player.play(equip_anim[weapon_index]))
            yield(anim_player,"animation_finished");equip = false

Do you know how you would integrate weapon picks ups into this code?

in Engine by (20 points)

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 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 webmaster@godotengine.org with your username.