Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by joop1996 · Jun 16, 2018 at 08:55 AM · 2d2d-platformerscriptableobjectscriptable object

Best way to make a ton of weapons,Best way to build a ton of weapons

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Captain_Pineapple · Jun 16, 2018 at 09:40 AM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joop1996 · Jun 16, 2018 at 10:18 AM 0
Share

Thanks for the reply! $$anonymous$$y weapons will be a bit different though. I am thinking about weird guns like freezerays and shrink guns. Would the same technique youre using work for that?

avatar image Captain_Pineapple joop1996 · Jun 17, 2018 at 12:09 PM 1
Share

Well yes in theory this is applicable. In my case the player can choose between grenades, lasers, normal bullets and "sniperProjectiles". These bullets are a script themselve that has a base damage value. Then the weapon modifies this damagevalue depending on attached weaponparts. As you can see for my case i have rather normal projectiles but they also have their own behaviour (splash damage/bulletdrop/projectilespeed)

You should probably have a weaponpart that describes your projectiles/lasers behaviour. So your weapon has a variable of type "ProjectileType". This will be your projectiles base class. Then you derive all the projectiles you want from this ProjectileType class. The thing they have in common? -> give them all a fire() function. Then you can have your player trigger the weapon which itself calls it's projectiles ´fire()´ function.

Then you can have your attached projectile do whatever it should do from the fire() function.

Normal bullet? spawn a prefab, apply velocity to it.

A laser? do a raycast, do some particle effects.

Special effects like freezing? Since you handle the raycast in the firefunction just apply the freezing effect from there. Or downscale the hit transform for shrinking.

You will have to code all bullet behaviour by hand in it's own script though.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

178 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Serialize a list of scriptable objects to Json 0 Answers

Instantiate with random scriptableObject 2 Answers

How can I make an object stop all momentum and hold it's position in air? 1 Answer

2D Mouse Aiming on Unity 4.3 1 Answer

2d enemy ai 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges