Search Unity

Create an advanced weapon system

Discussion in 'Scripting' started by Leos924, Mar 30, 2015.

  1. Leos924

    Leos924

    Joined:
    Feb 14, 2015
    Posts:
    11
    Hi,
    Someone knows how to do a Call of Duty style weapon system? Not exactly CoD system but an efficient system to use in multiplayer games because i know that you can hide the weapons and then show them when the player equips one, but this system uses too much resources if you use more than 15 different weapons and even is very difficult to keep an order if you are overlapping weapon over weapon so i want to know if there is any way to for example when the player takes a weapon from the floor or from dead enemies, the weapon destroys and instantiate another one from the same type in player hands and then set mecanim statemachine to fit that weapon animation or something similar and when the player changes weapon, it just disables render but not destroys itself.
    I dont know if someone understands and also sorry for my bad english but please help me in this.
    Thanks
     
  2. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    It sounds like you pretty much just answered your own question. Just instantiate your weapon prefab whenever it gets picked up/equipped, and then destroy it when it's unequipped.
     
    Kiwasi likes this.
  3. Leos924

    Leos924

    Joined:
    Feb 14, 2015
    Posts:
    11
    Yea but i want to know how to correctly instantiate the weapon (Correct position and rotation), and how to animate it within the character
     
  4. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    You just use Instantiate() to instantiate the weapon. You can then parent the weapon to the character's skeleton(hand bone probably) and it will follow it.
     
  5. Leos924

    Leos924

    Joined:
    Feb 14, 2015
    Posts:
    11
    Ok, then i will work on it and also find a good technique to animate correctly the weapon once instantiated.
    Thanks jRocket
     
  6. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    You use a custom Class like Item or Weapon, which includes things like the prefab to use when equipped, the correct position and rotation, and anything else that might be necessary (addon options, zoom ability, damage, mag size). As for animation, you either use Inverse Kinematics to bind the hands to the weapons grips, and animate the weapon, or you bind the weapon to the right hand and animate the arms for reloading etc. Both methods have their advantages and disadvantages, and there may also be options for combining both.
     
  7. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    Easiest technic I know to do this is to either have the model with pivot in the right position/rotation or to parent the model under a transform and make the relative position/rotation to this transfrom in such way that you can set its coordinates with the hand bone to zero position/rotation.
     
  8. Leos924

    Leos924

    Joined:
    Feb 14, 2015
    Posts:
    11
    Ok, well then i will try to make a script using this info and check the results :)