Hi there! Im building a 2d pvp platformer and Im planning to build a ton of drastically different weapons. My question is: what would be the best way to achieve this? Of course I could make tens of different weapon prefabs with tens of different scripts but something tells me theres a better way. Could someone point me in the right direction? Thanks!,Hey! I am building a 2D pvp platformer and Im planning to make a ton of drastically different weapons. My question is: what would be the most efficient way of doing this? I could obviously just make tens of different prefabs with tens of different scripts but I know there should be a more modular way. Could anyone point me in the right direction?
Hey there,
depends on what the differences between those weapons that you intend to have. So when you look at games like Borderlands or Fallout, a wepon consists of up to 7 Parts or something. Then you can have a pool of lets say 10 different parts for each Part-Type and randomly create a weapon out of this pool.
So given 7 different types (e.g. Barrel, Trigger, Grip, Stock, Sight, Magazin, Ammunition … ) with 10 different parts you could randomly put together 10.000.000 Weapons. Each can then either have a base stat or a modifier towards some weapon stat. For example the trigger could give you a base fire rate and the barrel and magazin will modify this value so that in the end the weapons stats are a combination of all the Parts values.
Limitations at this point are your creativity to what extend you can come up wth different parts and the balancing. In my current project i allow the user to build custom weapons from the system i described above. Balancing proves really difficult since there will be really crappy weapons and some overpowered ones and you might not be able to find these.
To implement this i’d suggest to first think about the construction of the weapons. You will Probably have some Weapon Class that is attached to some empty Transform. This will be the base of your weapons. Then each Weaponpart can be a subObject of this weapon and in the end look like a whole weapon. Since each barrel will be of different length you probably want to create some projectileorigin that is attached to the barrel wich gives you a direction to fire in and a point where you create Bullets.
I hope this helps so far. In case you have more questions feel free to ask.