0 votes

Hello Everyone
I'm currently working on a Weapon Pickup/Drop System. I had a few questions on how should I go on about doing this. I have these different types of weapons(pistol, shotgun, rifle, etc) that I've placed in the scene and want to pick them up by pressing the interact key. So far I have a basic gun in the game that I can interact with. How should I go about having different types of weapons and how would I reference them in my character for the logic. So far this is the script for the character and weapon interaction

extends Camera

# Global Variables
onready var InteractCast = $InteractCast
onready var WeaponCast = $WeaponCast
onready var Muzzle = $Hand/Weapon/GunModel/Muzzle
onready var Hand = $Hand

# Local Variables
var WeaponEquipped = false
var Weapon

func _ready():

func _physics_process(delta):
    if Input.is_action_just_pressed("Interact"):
        if InteractCast.is_colliding():
            var target = InteractCast.get_collider()
            if target.is_in_group("Weapons"):
                Weapon = target
                print("InteractRaycast Hit Weapon")
                WeaponEquipped = true
                print("InteractRaycast Collided With Something")
            print("InteractRaycast Did Not Collide With Anything")
    if Input.is_action_just_pressed("Drop"):
        if WeaponEquipped:
            WeaponEquipped = false
            print("Cant drop Weapon not Equipped!")

    if Input.is_action_just_pressed("FireWeapon"):
        if WeaponEquipped:
            if WeaponCast.is_colliding():
                var bullet = get_world().direct_space_state
                var collision = bullet.intersect_ray(Muzzle.transform.origin, WeaponCast.get_collision_point())
                if collision:
                    var target = collision.collider
                    if target.is_in_group("Enemies"):
                        print("Weapon Hit Enemy")
                    print("Weapon Hit Nothing")
in Engine by (15 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 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.