How would you have 1 soldier model and then change the weapon depending on what class is chosen without having to load all the weapons at once and without having to load a new soldier for every weapon?


You make a single soldier model. You make a number of weapons.

Then you would use something oft called a "hard point" (or "attach point" or many other things). You set such a point on the model's hand. You set another such point on the gun's grip. Now you can programmatically look up these points in the model data and mount the gun's grip in the soldier's hand (using either "model parenting" if you support such or just setting the world position of the gun appropriately). Because the soldier's hard point should be attached to a bone, the gun will stay in the soldier's hand during animation. You can now swap out the gun at will and place whichever gun you want in the soldier's hand with no additional work.

You may also have some animation data for the soldier to control when the hand is in a "hold a pistol" state or both arms and hands are in a "hold a rifle" state or the soldier is holding nothing and is in an "unarmed" state. You can blend these animation states with the other animations being used, or make a set of animations (running, idling, etc.) for each general class of gun. The complexity of the animations and desired level of realism/fidelity will determine how far you must go here.

You can go another step and programmatically animate the soldier model to the gun's dimensions using the hard points to determine where the hands should be placed and what general state they should be in so that the soldier smoothly works with any of a very wide variety of accurately modeled guns (not all rifles are held the same way). This is not the easiest thing to do by any stretch but is required if you want a very realistic game or have a very wide variety of gun types.

  • \$\begingroup\$ Thank you, this was an amazing explanation. My only question is how do you work with the animations like reload where the hands are involved but its gun specific? \$\endgroup\$ – user35165 Sep 16 '13 at 13:35
  • \$\begingroup\$ What you would do is create multiple reload animations. For example "reload_rifle", "reload_pistol", "reload_rocket", etc. Basically you want one item specific animation for each item classification (since most weapons share common structures you probably won't need more than 4 or 5 different animations). Once you have the proper animations for each weapon type you can either assign a reload animation to a weapon or use information already assigned to the weapon to derive the reload animation name. \$\endgroup\$ – Benjamin Danger Johnson Sep 16 '13 at 16:29
  • \$\begingroup\$ This was very well explained, so again, thank you. Is there a video tutorial on this so I can make sure I fully understand it? \$\endgroup\$ – user35165 Sep 17 '13 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.