I'm a beginner to Godot and I want to develop the skills necessary for making a decent weapon switching system in Godot for a first person shooter demo I'm trying to make; ideally I'll learn what it takes to make a first person shooter like Wolfenstein 3d or Doom with 3d models. I've already made a first person controller, I know how to make the guns fire and I also made a weapon switching system. However, the weapon switching system seems amateurish and I want it to be more improved. In order to give you guys of where I'm at, I'll say that I've been following tutorials by the Youtuber Garbaj, I've followed his tutorial on hitscans weapons, making a basic first person controller and switching weapons. I've also been following tutorials by Yotuber PandaDev on how to make a hitscan weapon and how to make an ammo system. PandaDev's videos are similiar to that of Garbaj but, he also taught me how to seamlessly integrate animations and interface element into the demo I'm working on. In order to understand where I am at this stage, I'd recommend look at the videos that have influenced me as it might be helpful in helping you to help me.
Here is my code for weapon switching (this piece of code is from the player controller script):
func weapon_select(): #Weapon Button Switching Code
if Input.is_action_just_pressed("weapon1") and not current_weapon == 1:
anim_player.play("pistol_equip")
current_weapon = 1
elif Input.is_action_just_pressed("weapon2")and not current_weapon == 2:
anim_player.play("shot_equip")
current_weapon = 2
elif Input.is_action_just_pressed("weapon3")and not current_weapon == 3:
anim_player.play("rifle_equip")
current_weapon = 3
if current_weapon == 1:
pistol.visible = true
pistol.shoot()
else:
pistol.visible = false
if current_weapon == 2:
shotgun.visible = true
shotgun.shoot()
else:
shotgun.visible = false
if current_weapon == 3:
rifle.visible = true
rifle.shoot()
else:
rifle.visible = false
Now here is the code I use for shooting the guns (this works well with the weapon switching system code):
extends Spatial
class_name weapon
export var damage = 10
export var ammo = 5
export var max_ammo = 5
export var fire_anim = "pistol_fire"
export var gun_action = "pistol fire"
export var reload_anim = "pistol_reload"
onready var aimcast = $"../../../Head/Camera/AimCast"
onready var anim_player = $"../../../AnimationPlayer"
onready var ammo_text = $"../../../Head/Camera/Control/ammo_count"
func _ready():
pass
func shoot():
if Input.is_action_pressed("fire"):
if ammo > 0:
if not anim_player.is_playing():
anim_player.play(fire_anim)
ammo -= 1
if aimcast.is_colliding():
var target = aimcast.get_collider()
if target.is_in_group("Enemy"):
target.health -= damage
print(gun_action)
#Reloading Code underneath here!
ammo_text.text = String(ammo)
if ammo <= 0:
anim_player.play(reload_anim)
ammo = max_ammo
if Input.is_action_just_pressed("reload") and ammo < 5:
anim_player.play(reload_anim)
ammo = max_ammo
What I did is I applied the shooting script to one of the guns(the pistol) and then I make the other guns inherit the exported variables from it in their own respect scripts and then swap out a few things to make each gun feel distinct. So now what do I want improved? Well, I want to implement weapon switching animations to my weapon switching code. However, I don't know how to completely do it. I've managed to implement weapon equipping animation but, only when it comes to switching the weapons with buttons, not when it comes to using the mouse wheel. I've also don't know how I'd integrate weapon unequipping animations into the code. The Youtuber Skyvastern has a tutorial on creating a fps weapon manager that does indeed use equipping and unequipping animations but, I don't want to follow his tutorial again as his weapon manager isn't to my liking (it's not old school as I want). I also don't know how to use Skyvastern's animation code in the weapon switching system created by Garbaj, as I don't really understand Skyvastern's animation code. Any serious help would be greatly appreciated in this endeavor. I've gone elsewhere for help on the internet. However, as I noob, the advice I received previously was difficult to understand. They're other things that I also need help with but, they're a lot of tutorials on those subject that I haven't explored yet. So for now, I'm focusing strictly on getting this weapon switching system improved. Again, any help would be appreciated.