• General Chat
  • How do you recommend I create my structure my class/gun system?

Hey everybody. I'm working on a third person shooter right now (actually based off a drawing my bro and me created when we were 12 and 8 years old respectively, lol) and am in the very early stages. I have a working tps controller that works well.

My current plan is to have around 4 classes for the player to choose from. Something like Assault, engineer, etc haven't figured out all of them yet. I think the classes will each carry 1 gun, although it may change to 2, and the player will be able to choose from a small selection of guns specific to each class.

So far, I have a scene which is my working 3rd person controller, which has a script with the basic movement. I am going to create a scene for each class, and add the controller scene to each class scene. My idea is that each class scene will have a script which deals with everything specific to the class.

How would you recommend I design the guns? Should I have a scene for each gun, and have my class script have a dictionary of all the gun scenes available to it for my player to choose from? Or is there a better way?

The game is multiplayer, btw although I don't think this will alter the design much.

If some of the structure I already have figured out doesn't make sense, feel free to let me know. I want a system that's flexible and isn't overthinking stuff. (For instance having a base gun and each gun deriving from that feels like overkill, it would be easier just to have a scene for each gun and just copy and paste code that is the same, although there won't be much) basically I'm trying to avoid a ton of heavy object oriented stuff because it gets confusing and difficult to work with after a while.

To anyone who read all of that, thank you, and if you want to hear more about the game (it's penguins with high tech gear shooting polar bears with high tech gear etc) feel free to comment!

Would each class/character have their own unique weapons only they use or does each class use all the weapons?

If each class/character has their own weapons and only they use them, I might have the weapon system be referenced individually be each character, where each character has a reference to all the possible gun scenes and then manages (and calls functions on) the weapons as required. Especially if you are looking to avoid using a base class, this would be one way you can keep the code clean while not needing to worry about what weapon extends what class, etc, as you can directly reference each weapon type and data in the character itself.

If each class/character can use all the weapons, then it's a little harder I would say. In this case, what I might recommend doing is using an autoload that has a reference to all the data for each weapon, and then have each character script reference the autoload to spawn/use the weapons. That way you only need to edit the weapon scene itself and the autoload to apply a change to the weapon across all characters for small tweaks like damage changes. You could also use the autoload for spawning weapons as well, which could be useful for placing weapons in a scene or spawning weapons on the player itself (like spawning the weapon in the player's hands, for example).

However, what I would personally do in either case is make a base weapon with some simple functions and the variables all weapons should have, and then extend the base class for each weapon. That way you have a consistent interface for each weapon, so you can use some semi-polymorphic code to write the system in the character script so every weapon works without needing to know the specifics of the weapon itself. That said, it can be tricky to do and I totally understand not wanting to go down this route if you are looking to avoid the complexities that object oriented programming can bring.

At the end of the day, what I would recommend doing is whatever you feel most comfortable with and/or think is the best for your game. :smile:

Thanks @TwistedTwigleg ! That's great advice and now I have some great guidlines for my structure. Thanks for taking the time to make such a detailed answer! P.S. When you create a base class and extend it for specific weapons, is the base class a scene, and the extended ones just altered versions of the scene? I may or may not use this method, but I would like to make sure, I'm sure I'll use this someday. Thanks!

lol, that comment makes me sound like such a noob, lol. I know how to do stuff like this in Godot ( or at least how to find out) , but since Godot doesn't really use terminology like class and extend class like Unreal, I wanted to make sure I was understanding you correctly.

@OpinionatedGamer said: Thanks @TwistedTwigleg ! That's great advice and now I have some great guidlines for my structure. Thanks for taking the time to make such a detailed answer! P.S. When you create a base class and extend it for specific weapons, is the base class a scene, and the extended ones just altered versions of the scene? I may or may not use this method, but I would like to make sure, I'm sure I'll use this someday. Thanks!

It can be a scene, or it can just be a script, whichever works best for you. I've seen it both ways, each with their pros and cons.

Personally, I generally just extend a script and use exported NodePaths to get the nodes the script needs, so as long as in the editor I plug it into the correct nodes, I can use it with any scene structure. That way then I can have it as an altered base scene or as a completely different scene but with a script that extends it, opening up the options on how to use it a bit. It does come with the downside of a lot of export(NodePath) var path and var node = get_node(path) lines of code to get all the nodes from the various node paths.

For extending the scripts, I generally use the class_name syntax:

extends Node
class_name base_class
var test = "hello"

# then to extend it
extends base_class
func _ready():
	print (test + " world")

You can also use the file path to the script though:

extends "res://scripts/base_calss.gd"
func _ready():
	print (test + " world")

@OpinionatedGamer said: lol, that comment makes me sound like such a noob, lol. I know how to do stuff like this in Godot ( or at least how to find out) , but since Godot doesn't really use terminology like class and extend class like Unreal, I wanted to make sure I was understanding you correctly.

Nah, I gotcha! I didn't think it was a "noob" quesiton or anything :smile: Hopefully my answer made sense, but if it didn't please let me know and I'll try to better explain.

Hey, @TwistedTwigleg! Your answer made sense to me, but I just started coding and immediately realized that I just do not feel comfortable enough with programming in godot to tackle something this big, lol. I have a ton of trouble sticking with small projects, but at this point I need to start small and build my skills. Thanks for your answers, I'll probably use them once I feel like I know what I'm doing, lol. I've programmed as a hobby for years, but I still struggle a ton, probably due to lack of putting my knowledge to practice. Anyway, thanks again, and my apologies. =)

@OpinionatedGamer said: Hey, @TwistedTwigleg! Your answer made sense to me, but I just started coding and immediately realized that I just do not feel comfortable enough with programming in godot to tackle something this big, lol. I have a ton of trouble sticking with small projects, but at this point I need to start small and build my skills. Thanks for your answers, I'll probably use them once I feel like I know what I'm doing, lol. I've programmed as a hobby for years, but I still struggle a ton, probably due to lack of putting my knowledge to practice. Anyway, thanks again, and my apologies. =)

No reason to apologize! It’s complicated even if you have lots of programming experience because of how many parts it has. I’ve tried, failed, and ultimately shelved many FPS attempts myself due to complexities.